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

109 Correlated Subqueries

Correlated subqueries contain a reference to a table in the outer query and are executed once for each row in the outer query, allowing the subquery to return a different result for each row. They can be used with logical and IN/ANY/ALL operators when the subquery needs to return varying results. WHERE EXISTS and WHERE NOT EXISTS test for the existence or non-existence of records in a subquery and are often used with correlated subqueries.

Uploaded by

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

109 Correlated Subqueries

Correlated subqueries contain a reference to a table in the outer query and are executed once for each row in the outer query, allowing the subquery to return a different result for each row. They can be used with logical and IN/ANY/ALL operators when the subquery needs to return varying results. WHERE EXISTS and WHERE NOT EXISTS test for the existence or non-existence of records in a subquery and are often used with correlated subqueries.

Uploaded by

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

Correlated Subqueries

• A correlated subquery contains a reference to a table in the outer query

• In a normal subquery the inner subqueries run first and execute once, they
return values for the outer subquery
• In a correlated subquery the subquery is executed once for each row in the
outer query
• Correlated subqueries can be used when the subquery needs to return a
different result for each row in the outer query
• Correlated subqueries can be used with logical operators (<,>,=…) and IN,
ANY, ALL operators
Where Exists / Not Exists
• WHERE EXISTS is used to test the existence of any record in a
subquery, and returns TRUE if the record exists

• WHERE NOT EXISTS is used to test the non-existence of any


record in a subquery, returns TRUE if record doesn’t exist

• Usually used with correlated subqueries

You might also like