correlated subquery

A subquery that refers to a column of the outer query's current row, so its answer differs row by row.

In more detail

WHERE EXISTS (SELECT 1 FROM orders AS o WHERE o.customer_id = c.id) asks, for each customer c, whether any order points at them. Logically it runs once per outer row, although the planner may execute it more cleverly.

Related terms

Taught in

References