Cellwise · SQL track
Checking for matches with EXISTS
Find rows that do, or don’t, have a match elsewhere.
EXISTS asks a yes-or-no question: does the subquery return any rows? It’s the natural way to ask “customers who have ordered” or, with NOT EXISTS, “customers who never have”.
The subquery usually refers back to the outer row, as in o.customer_id = c.id. That link is what makes it check each customer separately.
What you’ll do
- Customers who have ordered
- Customers with nothing paid
- People who manage someone