← Back ← AVG / model EXCEPT / INTERSECT →

Correlated subquery

Inner SELECT references the outer row — “am I above my department average?”

SQL drill • Subqueries

employees(id, name, dept_id, salary). List employees whose salary is greater than the average salary in their own department. The subquery repeats for each outer row because it mentions e.dept_id.

Pattern
WHERE col > (SELECT AVG … WHERE inner.dept = outer.dept)
Step 0/5Line
Outer scan + per-row inner average
Press Step or Play.
Ready
Correlation = inner query uses a column from the outer scope.