Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 (Beginner) question concerning joins / deletion

Author  Topic 

SwanAL
Starting Member

5 Posts

Posted - 2013-09-06 : 10:42:50
Hi all,

I have a question:

table 1 is:

number | name
1 | a
2 | b
3 | c

table 2 is:
number | code
1 | abc
1 | def
3 | zui

as you see, in table 2 "number" is not unique and can have double entrys

now I want to join these tables:
1.) i dont want any double "number"
2.) I only want entrys which are mentione in table 2

so as the result I want:

number | name
1 | a
3 | c

How has the join to look like?

Or if there is no working join, how could I delete all entrys in table 2 where there are several "number" (but one entry)

Hope everything is clear.

Thanks for your help and kind regards,

SwanAL

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-09-06 : 11:11:46
You can write the query a few different ways - for example:
SELECT number, name
FROM Table1 a
WHERE EXISTS (SELECT * FROM Table2 b WHERE b.number = a.number);
Go to Top of Page
   

- Advertisement -