On June 18th at 10:00 AM UTC Academy will be unavailable for 5 minutes due to planned maintenance break.
Rainbow Deals - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Very simple subqueries
6. Subqueries with various logical operators
Subqueries with multiple results
Correlated subqueries
Other subqueries

Instruction

Excellent! Subqueries can also be used with other logical operators. Take a look at the following example:

SELECT
  * 
FROM mountain 
WHERE height > (
  SELECT height 
  FROM mountain 
  WHERE name = 'Zugspitze'
);

The above query will return all mountains which are higher than Zugspitze. As you can see, we've used the 'greater than' sign (>) together with a subquery.

Exercise

Find the names of all cities have a population lower than Madrid.

Stuck? Here's a hint!

Type:

SELECT
  name 
FROM city 
WHERE population < (
  SELECT
    population 
  FROM city 
  WHERE name = 'Madrid'
);