SELECT left_tbl.*
FROM left_tbl LEFT JOIN right_tbl ON left_tbl.id = right_tbl.id
WHERE right_tbl.id IS NULL;
The code above works beautifully when you are searching rows from left table without a counterpart in one right table.
But how do I find rows from left table without a counterpart in two right tables?
If I understand correctly, you want to find records in
LEFT_TBLthat doesn’t exist in both of the two other tables? The most readable would be:Using LEFT JOIN/IS NULL:
If you want
LEFT_TBLrecords that do not exist in one of the two tables, change theANDin theWHEREclause toOR.