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

Instruction

Outstanding! Since you're doing so well, you should be ready for another operator. Check out this example:

SELECT
  *
FROM Country
WHERE Country.Area > ALL (
  SELECT
    City.Area
  FROM City
);

As you can see, we've got a new operator, ALL, on the right side of the logical operator >. In this case, '> ALL' means 'greater than every value in the parentheses.'

As a result, we'll get all countries that are bigger (in terms of area) than all cities in our database. Liechtenstein, for instance, is a very small country. It is bigger than some cities (like Lyon, for example), but it is not bigger than every city (Berlin is bigger, for example), so it won't be shown in the result.

You can also use ALL with other logical operators: = ALL, =! ALL, < ALL, <= ALL, or >= ALL.

Exercise

Find all information about cities that are less populated than all countries in the database.

Stuck? Here's a hint!

Type:

SELECT
  *
FROM City
WHERE City.Population < ALL (
  SELECT
    Country.Population
  FROM Country
);