SQL Correlated Subqueries


Correlated (also known as Synchronized or Coordinated) Subqueries are nested queries that make references to the current row of their outer query:

SELECT EmployeeId
    FROM Employee AS eOuter
    WHERE Salary > (
       SELECT AVG(Salary)
       FROM Employee eInner
       WHERE eInner.DepartmentId = eOuter.DepartmentId

Subquery SELECT AVG(Salary) ... is correlated because it refers to Employee row eOuter from its outer query.