Correlated Nested Queries in SQL

For Complete YouTube Video: Click Here

This class will try to understand Correlated Nested Queries in SQL.

We have already discussed the concepts of JOINS in our previous class.

Correlated Nested Queries in SQL

Correlated nested queries are for row-by-row processing.

Each nested sub-query is executed once for every row of the outer query.

A correlated nested query reads every row in a table and compares values in each row against related data.

Query

Write a query to find all the employees who earn more than the average salary in their department.

We have to consider the employee table shown below to get the output.

Each row is taken and compared from the above table with all the rows in the table.

Wherever the condition is ‘true,’ the required columns from the tables will be considered to display.

The query and the output are shown below.

Correlated Nested Queries in SQL 1
Correlated Nested Queries 1