Lets say I have table A, with an id column, and table B with an A_id column. A_id is a foreign key of id. Now, if I want to get all id’s from A of which B has a foreign key link, I can do
SELECT id FROM A JOIN B ON id = A_id
However, how can I select all id’s from A where B does not link to? (without selecting all id’s and subtracting the above subset from that)
This will use an anti-join: for each record from
a, it will searchbfor the record’sid(using an index onb.a_id) and if none found, return the record.