IN and EXISTS

IN tests whether a value belongs to the set returned by a subquery, EXISTS tests whether the subquery returns at least one row. EXISTS stops at the first row found and handles NULLs well, which makes it safer than NOT IN for expressing an absence.

Example

WHERE EXISTS (SELECT 1 FROM commandes o WHERE o.client_id = c.id)

Related concepts

The whole glossary