SQL Tutorial · SQL Basics · Lesson 9 of 36

SQL IN and BETWEEN

Match a list of values with IN and a range with BETWEEN.

IN

IN is shorthand for several OR conditions:

Example 1Try it yourself
SELECT name, country FROM customers WHERE country IN ('UK', 'Japan', 'Switzerland');

Output

name | country
Ada Lovelace | UK
Alan Turing | UK
Tim Berners-Lee | Switzerland
Yukihiro Matsumoto | Japan

IN also accepts a subquery — covered in Subqueries.

BETWEEN

BETWEEN a AND b is inclusive on both ends:

Example 2Try it yourself
SELECT name, price FROM products WHERE price BETWEEN 20 AND 40;
SELECT order_id, order_date FROM orders WHERE order_date BETWEEN '2026-02-01' AND '2026-02-28';

Output

name | price
SQL for Beginners | 29.99
Clean Code | 37.5
Wireless Mouse | 24.99
USB-C Hub | 39.95

order_id | order_date
3 | 2026-02-02
4 | 2026-02-14
5 | 2026-02-28

Careful with dates that include a time: BETWEEN '2026-01-01' AND '2026-01-31' misses '2026-01-31 14:00'. The safe pattern is >= start AND < next_day.

Test yourself

Is BETWEEN 10 AND 20 inclusive of 10 and 20?

  1. Yes, both ends
  2. No, neither end
  3. Only 10
  4. Only 20
Show answer

Answer: Yes, both ends