FAQ: Subqueries - Correlated Subqueries I

#1

This community-built FAQ covers the “Correlated Subqueries I” exercise from the lesson “Subqueries”.

Paths and Courses
This exercise can be found in the following Codecademy content:

SQL: Table Transformation

FAQs on the exercise Correlated Subqueries I

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

#3

I don’t understand the importance of
WHERE carrier = f.carrier

Could someone explain please?

3 Likes
#4

The average value is calculated based on “carrier”, it is already compared with “distance”

2 Likes
#5

This was confusing for me too.

I think since SQL is accessing the same table “flights” and column “distance” based on carriers SQL needs to distinguish the difference between the two. One instance of carriers is holding all the distances as “f.carrier” while the the other is holding the average (AVG) distances as just “carriers” so we are now comparing the two here: WHERE carrier = f.carrier I think SQL needs to be able to distinguish the two in order to use the < or > operators in the above query and give us the appropriate id associated to those carriers who are above or below average.

This is basically what @smilexdrus has stated and what I think I understood from it. I’m just trying to be more explanatory about it.

2 Likes
#6

Why is there the following?
f.origin = flights.origin

Aren’t they both referring to the same chart and data?

#7

My understanding is that this will calculate the average distance for each carrier every time it comes up in the flight list.
i.e. the average for each carrier is calculated multiple times.

Is that true?
If so, is this a wasteful/slow way of doing it?
If so, how would you go about doing it otherwise? Would you create a table of carrier names and averages then look up the value in that? Would that actually speed things up?

Thanks in advance,
Alex