James W. Walker wrote:
Let's say I have two tables A and B, each of which has an integer ID column. I want to find ID values that occur in A but not B. The first query I came up with was:

SELECT ID FROM A WHERE NOT EXISTS (SELECT * FROM B WHERE B.ID = A.ID);

but I get a syntax error.  My next try,

SELECT ID FROM A WHERE ID NOT IN (SELECT ID FROM B);

works and is probably more efficient, but I'm just curious what's wrong with the first one.

Not sure whether the following is more efficient, but it is easier on the eyes:

SELECT ID FROM A EXCEPT SELECT ID FROM B;


HTH,

Gerry

Reply via email to