Introduction
Very simple subqueries
Subqueries with multiple results
Correlated subqueries
16. The operator EXISTS with NOT
Other subqueries

Instruction

Good! Remember the operator NOT? We can use it together with EXISTS. Take a look:

SELECT
  * 
FROM city 
WHERE NOT EXISTS (
  SELECT
    * 
    FROM trip 
    WHERE city_id = city.id
);

As you probably predict, this query will find all cities that don't have a trip organized to them.

Exercise

Select all mountains with no hiking trips to them.

Stuck? Here's a hint!

Type:

SELECT
  * 
FROM mountain 
WHERE NOT EXISTS (
  SELECT
    * 
  FROM hiking_trip 
  WHERE mountain_id = mountain.id
);