Deals Of The Week - 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 which 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'
);