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 operator IN with subqueries
Correlated subqueries
Other subqueries

Instruction

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

SELECT price
FROM trip
WHERE city_id IN (
  SELECT id
  FROM city
  WHERE population < 2000000
);

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

In this way, we can find prices of trips to cities with a population lower than 2 million.

Exercise

Find all information about all trips in cities whose area is greater than 100.

Stuck? Here's a hint!

Type:

SELECT *
FROM trip
WHERE city_id IN (
  SELECT id
  FROM city
  WHERE area > 100
);