Subquery
Also called: Nested query, EXISTS, NOT EXISTS
A query inside another query, such as a list for IN, a check for EXISTS, or a single value used like a column.
Definition
Testers use EXISTS and NOT EXISTS subqueries for questions like "delivered but never paid" or "customers without orders". NOT IN with a subquery returns no rows at all if the subquery's list contains a NULL, so NOT EXISTS is the safer choice.
In practice
WHERE NOT EXISTS (SELECT 1 FROM payments p WHERE p.order_id = o.id AND p.status = 'succeeded')
Learn it in context
Lessons that use this term.