Non-Correlated Subqueries I

Nice work! Let's continue with subqueries.

Imagine that you are the head of air traffic control. In our airplanes database, you'd like to know which flights had an origin airport with an elevation greater than 2000 feet. We can do this with a subquery.

We first create an inner query, or subquery, that finds the airports with elevation greater than 2000 from the airports table:

SELECT code 
  FROM airports 
  WHERE elevation > 2000;

Next, we take the result set of the inner query and use it to filter on the flights table, to find the flight detail that meets the elevation criteria.

FROM flights 
WHERE origin in (
    SELECT code 
    FROM airports 
    WHERE elevation > 2000);

As shown above, a subquery is nested within another query to give us our desired result.

Community Forums
Get help and ask questions in the Codecademy Forums
Report a Bug
If you see a bug or any other issue with this page, please report it here.