BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
spandya
Calcite | Level 5

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Because flightattendants.empid is defined outside of the subquery (i.e. in the main query).

PG

View solution in original post

4 REPLIES 4
PGStats
Opal | Level 21

Because flightattendants.empid is defined outside of the subquery (i.e. in the main query).

PG
spandya
Calcite | Level 5
In other words its because the certadv.flightattendants is in the outer query? If it was replaced with another dataset instead (that also had the empID variable) and the subquery was kept the same, would it become non-correlated?
PGStats
Opal | Level 21

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.

PG
spandya
Calcite | Level 5
Interesting. I couldn't come up with an example for an uncorrelated subquery that uses the EXIST operator. Which made me question the definitions again hence the post.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Autotuning Deep Learning Models Using SAS

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.

Discussion stats
  • 4 replies
  • 2254 views
  • 1 like
  • 2 in conversation