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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 1845 views
  • 1 like
  • 2 in conversation