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
 exclude a table from another table

Author  Topic 

goligol
Posting Yak Master

128 Posts

Posted - 2011-07-28 : 12:50:28
I have table A and table B,
I want to see the records in table B which are not in table A:


select B.*
from dev.xListOfChildrenOffile25 B

,dev.xListOfChildrentAlList A


where not (B.O = A.O
and B.D = A.D
and B.M = A.M
and B.C = A.C)

But it does not return correct records.

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-07-28 : 12:54:55
If those are the only columns in your table (and if you are on SQL 2005 or higher, you can use the EXCEPT keyword:

select * from dev.xListOfChildrenOffile25
EXCEPT
select * from dev.xListOfChildrentAlList

If there are more columns, you can list the columns that you want to compare instead of using the *.
Go to Top of Page

goligol
Posting Yak Master

128 Posts

Posted - 2011-07-28 : 13:28:43
Thank you. it works:)
Go to Top of Page
   

- Advertisement -