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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 (Beginner) question concerning joins / deletion
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

5 Posts

Posted - 09/06/2013 :  10:42:50  Show Profile  Reply with Quote
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,


James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 09/06/2013 :  11:11:46  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000