Anti-join

An anti-join selects the rows of a table that have no match in another, for example customers with no orders. It is written with LEFT JOIN ... WHERE right.id IS NULL or with NOT EXISTS. Avoid NOT IN if the subquery can return NULLs.

Example

SELECT c.* FROM clients c
LEFT JOIN commandes o ON o.client_id = c.id
WHERE o.id IS NULL;

Related concepts

The whole glossary