The most effective answer is to use a left join, since using "NOT IN" can sometimes prevent the query from using the index, if any.
The answer in this case will be similar to
SELECT DISTINCT * FROM TableA a LEFT JOIN TableB b ON a.Id = b.Id WHERE b.Id IS NULL
Alternatively, this is more readable than a left join, and more efficient than NOT IN solutions.
SELECT * FROM TableA a where NOT EXISTS (SELECT * FROM TableB where Id = a.Id)
source share