An anti-join finds rows from one table that do not have a match in another table.
Example: customers who never placed an order.
Method 1: NOT EXISTS
SELECT *
FROM customers c
WHERE NOT EXISTS (
SELECT 1
FROM orders o
WHERE o.customer_id = c.id
);Method 2: LEFT JOIN
SELECT c.*
FROM customers c
LEFT JOIN orders o
ON c.id = o.customer_id
WHERE o.customer_id IS NULL;Interview shortcut:
> Anti-join = give me rows that don't have a match.