109 Correlated Subqueries
109 Correlated Subqueries
• 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