Exclusion Joins (Anti-Joins)
7. Exclusion Joins (Anti-Joins)
Section titled “7. Exclusion Joins (Anti-Joins)”These are not a separate join type — they’re a pattern built on top of LEFT or FULL OUTER JOIN. The goal is to find rows that have no match in the other table.
Find employees with no department
Section titled “Find employees with no department”SELECT e.nameFROM employees eLEFT JOIN departments d ON e.dept_id = d.dept_idWHERE d.dept_id IS NULL;-- Result: Carol, DavidFind departments with no employees
Section titled “Find departments with no employees”SELECT d.dept_nameFROM departments dLEFT JOIN employees e ON e.dept_id = d.dept_idWHERE e.id IS NULL;-- Result: FinanceHow it works: After a LEFT JOIN, rows with no match on the right side have
NULLfor all right-table columns. FilteringWHERE right_table.id IS NULLisolates exactly those unmatched rows.