Non-Correlated Subqueries I


#1

Hi
When determining which airports are >2000 elevation, they used:
SELECT code
FROM airports
WHERE elevation > 2000;

1) What is the significance of specifying the "code" column? This leads to my next question...

When determining which flights originated from airports>2000, they use:
SELECT *
FROM flights
WHERE origin in (
SELECT code
FROM airports
WHERE elevation > 2000);

The 'origin' from flights dictate a specific airport name while 'code' from airports dictate a specific airport. How are they connected/logic behind it?


#2

I think that the 'code' column in the 'airports' table is functionally equivalent to the 'origin' column in the 'flights' table. That is, every airport has a unique 'code' attached to it and every flight has a unique 'origin' defined by the 'airports' code.


#3

I am a fellow learner, but I agree with kemini. My understanding is that the database is first going through the "airports" table and returning the "code" from all entries (airports) where the elevation is greater than 2000. The outer query then goes through "flights" and identifies which entries origins are contained in the list it created.


#4

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