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 = N'Zugspitze'
);

The above query will return all mountains that are taller than Zugspitze. As you can see, we've used the greater-than operator (>) within the subquery.

Exercise

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

Stuck? Here's a hint!

Type:

SELECT
  City.Name
FROM City
WHERE City.Population < (
  SELECT
    City.Population
  FROM City
  WHERE City.Name = N'Madrid'
);