The Advanced Programming prep guide distinguishes correlated and non-correlated subqueries with the following definitions.
A noncorrelated subquery is a self-contained subquery that executes independently of the outer query. The simplest type of subquery is a noncorrelated subquery that returns a single value.
correlated - A dependent subquery is one that requires one or more values to be passed to it by the outer query before the subquery can return a value to the outer query.
Later on, however, they mention the following SQL query being a correlated subquery but how can that be? How is the subquery in this case dependent on the outer query?
The following PROC SQL query accomplishes this task by using a correlated subquery and the NOT EXISTS operator.
proc sql;
select lastname, firstname
from certadv.flightattendants
where not exists
(select * from certadv.flightschedule where
flightattendants.empid= flightschedule.empid);
quit;
Because flightattendants.empid is defined outside of the subquery (i.e. in the main query).
Because flightattendants.empid is defined outside of the subquery (i.e. in the main query).
If the subquery was uncorrelated it could only refer to variables from datasets mentioned in its FROM clause. It's hard to imagine a case where an EXISTS operator would refer to an uncorrelated subquery.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Follow along as SAS’ Robert Blanchard explains three aspects of autotuning in a deep learning context: globalized search, localized search and an in parallel method using SAS.
Find more tutorials on the SAS Users YouTube channel.