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
 Querying tables against eachother?

Author  Topic 

Tototo1
Starting Member

22 Posts

Posted - 2012-03-14 : 16:58:32
I am trying to get back data from one table that does not exist in another. I have Table #aaa with 1000 records and table ###b with 400 records. I want to return all values in table #aaa that are not in #bbb. Is there an easy way to do such a query? Thanks!

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-03-14 : 17:06:22
SELECT * FROM #aaa
EXCEPT
SELECT * FROM ###b
Go to Top of Page

Tototo1
Starting Member

22 Posts

Posted - 2012-03-15 : 10:49:58
Wow that was simple. Thanks!
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-03-15 : 12:40:52
Is EXCEPT ANSI?

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-15 : 15:25:38
[code]
SELECT * FROM #aaa a
WHERE NOT EXISTS(SELECT 1 FROM #bbb WHERE relcol=a.relcol)
[/code]

relcol should be substitued by column through which tables are related

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -