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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Comparing two tables

Author  Topic 

sqltrouble
Starting Member

2 Posts

Posted - 2006-10-12 : 17:57:39
How do I find records in table A that are not in table B?

Select ID from tableA where tableA.ID NOT IN (Select ID from tableB) is not working.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-10-12 : 19:43:31
Use NOT EXISTS.

Tara Kizer
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-10-12 : 21:14:54
>>Select ID from tableA where tableA.ID NOT IN (Select ID from tableB) is not working.

Why?
Did you get wrong results?
Did you get error?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-10-12 : 22:42:15
Try this:

select
ID
from
tableA
where
tableA.ID NOT IN
(
Select
ID
from
tableB
where
ID is not null

)



CODO ERGO SUM
Go to Top of Page

sqltrouble
Starting Member

2 Posts

Posted - 2006-10-13 : 12:34:47
Thank you Michael. That did it!
Go to Top of Page
   

- Advertisement -