IN and BETWEEN
SQL · Unit 2: Filtering
- Full plan
- SQL
- 10 exercises
Delivery grew: besides Boston and Tampa, it now reaches Austin. With OR that's already three conditions that are almost the same, and with ten cities nobody would want to read them.
IN asks whether the value is in a list. The list goes in parentheses, with its values separated by commas.
SELECT name, city
FROM customers
WHERE city IN
('Boston', 'Tampa', 'Austin');Returns
| name | city |
|---|---|
| Luke | Austin |
| Mason | Tampa |
| Dylan | Boston |
| Hannah | Austin |
The rest of the explanation is in the lesson, which is part of the full plan.
Exercises in this lesson
You do them in the app, which checks them on the spot and explains why.
1. Multiple choice
Which condition lets through exactly the same rows as
city IN ('Denver', 'Tampa')?2. Complete the code
Last lesson, a customer wanted to see Audio and Devices, and the query repeated the column. Fill in the blank for the short version.
3. Put the lines in order
The products with ids 5 and 6, the two devices, are sold with a warranty. Put in order the query that shows the id and the quantity of the orders that come with one. Two lines don't belong.
4. Predict the output
The store has four categories. What does this query return?
5. Predict the output
Here both edges of the range land on a product. There are 5 Monitors left and 15 Headphones. What does this query return?
6. Complete the code
Today the stock clerk restocks whatever has between 3 and 12 units. Fill in the blanks for the range.
7. Predict the output
Today is January 15, 2026. What does this query return?
8. Find the bug
Orders of 2 to 5 units get a quantity discount, and the list should have five. It has four. Order 8, which was 3 units, is missing. Which line has the problem?
9. Put the lines in order
The gift flyer lists everything that costs 20 to 100 and can be delivered today. Put the query in order. One line doesn't belong.
10. Write the code
The next campaign is for customers ages 27 to 38, counting the ones who are 27 and the ones who are 38. Write a query that shows their
nameand theirage, in that order.
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.