How do I get all the rows in one table that are not in another in MS Access? How do I get all the rows in one table that are not in another in MS Access? sql sql

How do I get all the rows in one table that are not in another in MS Access?


SELECT TableB.con_numberFROM TableBWHERE NOT EXISTS (SELECT 1                   FROM TableA                   WHERE TableA.con_number = TableB.con_number);


NOT IN version (slow but sure):

SELECT con_numberFROM TableBWHERE con_number NOT IN (SELECT con_number FROM tableA);

experimental version (don't know if this is any faster, just try it out):

SELECT B.con_number, MAX(A.con_number) AS checkFROM tableB B LEFT JOIN tableA A ON B.con_number = A.con_numberGROUP BY B.con_numberHAVING check IS NULL;

Note: Both should be fairly standard SQL, I don't know any ms-access specific features


There is a Find Unmatched wizard that will set this up. The SQL is:

SELECT TableB.con_numberFROM TableB LEFT JOIN TableA ON TableB.con_number = TableA.con_numberWHERE TableA.con_number Is Null