Home › Learn › SQL › Shaping results

IN and BETWEEN

Lesson 8 of 26. Match a list of values, or a range.

category IN ('accessories', 'stationery') is shorthand for a chain of OR equalities. price BETWEEN 10 AND 40 is shorthand for price >= 10 AND price <= 40; both ends are included. Both read better than the long form and both can be negated: NOT IN, NOT BETWEEN.

IN also accepts a subquery instead of a fixed list, which becomes powerful once you reach the joins module.

SELECT name FROM employees WHERE dept IN ('Sales', 'Support') AND salary BETWEEN 4500 AND 5500;

Your task

Show the name and price of products in the accessories or stationery categories that cost between 10 and 40 inclusive.

Hint 1

category IN ('accessories', 'stationery') AND price BETWEEN 10 AND 40

Show the solution
SELECT name, price FROM products WHERE category IN ('accessories', 'stationery') AND price BETWEEN 10 AND 40;

    Runs SQLite compiled to WebAssembly in this tab; the database is rebuilt before every run.