Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Very simple subqueries
Subqueries with multiple results
9. The IN operator with subqueries
Correlated subqueries
Other subqueries

Instruction

Okay! Now, you're probably wondering how to use the new IN operator with subqueries. Consider the following example:

SELECT
  Trip.Price
FROM Trip
WHERE Trip.CityID IN (
  SELECT
    City.ID
  FROM City
  WHERE City.Population < 2000000
);

In this subquery, we look for the IDs of all cities with a population of less than 2 million. Next, we use these IDs as the values in the IN operator.

In this way, we can find the prices of trips to cities with fewer lower than 2 million people.

Exercise

Find all information about all trips in cities with an area exceeding 100.

Stuck? Here's a hint!

Type:

SELECT
  *
FROM Trip
WHERE Trip.CityID IN (
  SELECT
    City.ID
  FROM City
  WHERE City.Area > 100
);