Alternative to NOT EXISTS

Posted by Dave Colwell on Stack Overflow See other posts from Stack Overflow or by Dave Colwell
Published on 2010-04-30T05:04:41Z Indexed on 2010/04/30 5:07 UTC
Read the original article Hit count: 219

Filed under:
|

Hi all,

I have two tables linked by an ID column, lets call them Table A and table B. My goal is to find all the records in table A that have no record in table B. For instance:
Table A:
ID----Value
1-----value1
2-----value2
3-----value3
4-----value4

Table B
ID----Value
1-----x
2-----y
4-----z
4-----l

As you can see, record with ID = 3 does not exist in table B, so i want a query that will give me record 3 from table A. the way i am currently doing this is by saying AND NOT EXISTS (SELECT ID FROM TableB) but since the tables are huge, the performance on this is terrible. Also, when i tried using a Left Join where TableB.ID is null, it didnt work. Can anyone suggest an alternative?

© Stack Overflow or respective owner

Related posts about sql

Related posts about sybase