thinQmaster Virtual testing partner Adaptive practice exams that find your weak spots and drill them. Every answer explained. From $69
Enroll

thinQmaster

Find your exam

Five questions free, before you decide.

Step 1 · choose a vendor

In one of our camps? Your practice exams come with the tuition — they are on your study page already.

Data & Analytics · Intermediate

Correlated Subquery

A subquery that references columns from the outer query and is logically evaluated once per outer row.

Definition

Because it depends on the outer row, a correlated subquery can be slow on large tables unless the optimizer rewrites it as a join. It is commonly used with EXISTS or for per-row comparisons such as 'employees paid above their department average'.

Example

SELECT e.* FROM Employees e WHERE Salary > (SELECT AVG(Salary) FROM Employees WHERE DeptID = e.DeptID);

Exam tip

A subquery that references the outer table alias is correlated; window functions are often a faster alternative.

Related terms