2. Non-Correlated Subqueries I


#1

https://www.codecademy.com/courses/sql-table-transformation/lessons/subqueries/exercises/non-correlated-i?action=lesson_resume

I can pass the lesson no problem, but my issue is I'm not understanding why I'm passing. I don't see the relation between the 2 tables for flights and airports. I don't see the values from one table in the other. How does the flight know which airport it's taking off at?



Replace this line with your code.


#2

In the airports table, code is the airport code, and elevation is the elevation of that airport. This is the nested query. origin in the flights table corresponds to code in the airports table.


#3

I had the same issue but what mtf says is true.

Just try and do a JOIN of the two tables by airports.code = flights.origin and you'll see that.


#4

Thanks zzzmeu, your explanation is the best yet...

I see the relation with...

SELECT airports.code, flights.origin
FROM airports, flights
WHERE airports.code = flights.origin;

It's exactly the relation I thought it should be but what was throwing me off was when I would run...

SELECT code FROM airports;

It would return funny 4 digit codes such as S57, 19NY, Q85, 2KY3, etc. and I was looking for simple 3 digit letters such as JFK, SNA, MIA, SEA, etc.

With your explanation I now see this much more clearly. Was over-analyzing it. Sometimes the simplest explanation is the best. Gotta just trust the code.


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.