The easiest and easiest to read way to write what you are describing is:
SELECT * FROM 'B' WHERE 'ID' NOT IN (SELECT 'ID' FROM 'A')
However, you should be aware that using a subquery for something like this has historically been slower than doing the same with self-join , because it is easier to optimize the latter, which might look like this:
SELECT 'B'.* FROM 'B' LEFT JOIN 'A' ON 'A'.'ID' = 'B'.'ID' WHERE 'A'.'ID' IS NULL
However, the technology is constantly being improved, and the extent to which this is true (or even whether it matters) depends on the database software that you use .
You should test both approaches and then choose the best balance of readability and performance for your use case.
Lightness races in orbit
source share