0% found this document useful (0 votes)
69 views2 pages

Correlated Subqueries - Unit 3.5

Correlated subqueries depend on the outer query and execute once for each row selected by the outer query. They compare values in the outer query to an aggregate value calculated in the inner query for the same row. For example, a correlated subquery can find employees whose salary is greater than the average salary for their department by comparing each employee's salary to the average calculated for their department.

Uploaded by

Nishanthini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views2 pages

Correlated Subqueries - Unit 3.5

Correlated subqueries depend on the outer query and execute once for each row selected by the outer query. They compare values in the outer query to an aggregate value calculated in the inner query for the same row. For example, a correlated subquery can find employees whose salary is greater than the average salary for their department by comparing each employee's salary to the average calculated for their department.

Uploaded by

Nishanthini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Correlated Subqueries

 Opposite of Nested sub-queries.


 A correlated subquery is a subquery that depends on the outer query.
 That is, the where clause of the correlated subquery uses the data of the outer query.
 A correlated subquery executes once for each selected row from the outer query.
 A correlated subquery is also known as repeating subquery or synchronized subquery.

Eg:1 To select or find all the employees whose salary is greater than the average salary of
all employees in the department.

Select empID, empName from Employee AS emp


Where Salary >
(
Select AVG (Salary) from Employee
Where dept = emp.dept
);
Here, the outer query is:

Select empId, empName

From Employee AS emp

Where Salary > ……

And the inner query is:

Select AVG (Salary)

From Employee

Where dept = emp.dept;


Using EXISTS with a Correlated Subquery

You might also like