Check value exist in a table but not in another table

SQL to check a value exist in one table but not in another.

SELECT t1.name
FROM table1 t1
LEFT JOIN table2 t2 ON t2.name = t1.name
WHERE t2.name IS NULL

or this (not tested)

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

Leave a Reply

Your email address will not be published. Required fields are marked *