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

Instruction

Awesome! Let's learn another new operator, then. Consider the following:

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


EXISTS is a new operator. It checks if there are any rows that meet the condition.

In our case, the whole query will show only information for cities where there is at least one trip (where there exists a trip) organized by our travel agency. Cities with no trips will not be shown.

Exercise

Select all countries where there is at least one mountain.

Stuck? Here's a hint!

Type:

SELECT *
FROM country
WHERE EXISTS (
SELECT
*
FROM mountain
WHERE country_id = country.id
);