Find rows with no match
Customers who never ordered. NOT EXISTS is clear and fast.
SQL · Find rows with no matchIntermediate
SELECT c.id, c.name
FROM customers c
WHERE NOT EXISTS (SELECT 1 FROM orders o WHERE o.customer_id = c.id);
-- same result with LEFT JOIN
SELECT c.id, c.name
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id
WHERE o.id IS NULL;not existsleft joinis nullanti join