Subqueries
3 Topics
1
Scalar Subqueries
Subqueries that return a single value, usable in SELECT, WHERE, and HAVING.
Scalar subqueries are tested in interviews to evaluate understanding of when a subquery can appear (SELECT list, WHERE, HAVING), what happens when it returns more than one row, and how to rewrite scalar subqueries as JOINs for performance.
2
Correlated Subqueries
Subqueries that reference columns from the outer query, executing once per row.
Correlated subqueries are tested to evaluate understanding of row-by-row execution, performance implications, how they differ from non-correlated subqueries, and when to rewrite them as JOINs or window functions.
3
EXISTS, NOT EXISTS, and IN vs EXISTS
Checking for the presence or absence of related rows using subquery existence tests.
EXISTS vs IN is one of the most frequently asked SQL interview questions — interviewers test whether you understand short-circuit evaluation, NULL handling differences, performance characteristics, and when to choose one over the other.