Introduction
Very simple subqueries
Subqueries with multiple results
8. The IN operator
Correlated subqueries
Other subqueries

Instruction

Excellent! These examples are getting too easy for you! Let's try something more complicated.

So far, our subqueries have only returned single values (like 5 or 15.28, for example). Let's change that.

First, we need to learn a new operator. Take a look at the example:

SELECT
  *
FROM City
WHERE Rating IN (3, 4, 5);

Can you guess what IN means? That's right, it allows you to specify a few values in the WHERE clause instead of just one.

In our example, we only want to show interesting cities, but we're not very picky — any city with a rating of 3 OR 4 OR 5 will do. That's what IN (3, 4, 5) means.

Exercise

Find all information about hiking trips with a difficulty of 1, 2, or 3.

Stuck? Here's a hint!

Type:

SELECT
  *
FROM HikingTrip
WHERE Difficulty IN (1, 2, 3);