AnalystPracticeGuides
DashboardSign up

SQL IN and BETWEEN

IN matches any value in a list. BETWEEN matches a range, and it includes both ends. Both make a WHERE clause shorter and easier to read than a chain of OR or two comparisons.

How do you use IN?

SELECT * FROM orders
WHERE country IN ('AT', 'DE', 'CH');

IN also takes a subquery, for example customers who ordered in 2026:

WHERE customer_id IN (SELECT customer_id FROM orders WHERE order_date >= '2026-01-01')

How do you use BETWEEN?

WHERE amount BETWEEN 100 AND 500

includes 100 and 500.

Why does BETWEEN with dates miss the last day?

If the column stores a time, BETWEEN '2026-01-01' AND '2026-01-31' stops at midnight at the start of 31 January. Use a half-open range instead:

WHERE order_date >= '2026-01-01' AND order_date < '2026-02-01'

The NOT IN NULL trap

If the list from a subquery contains a NULL, NOT IN returns no rows at all. Use NOT EXISTS, or add WHERE column IS NOT NULL to the subquery.

Try it yourself. Practise this in a real database in your browser, with instant feedback.
Practise IN and BETWEEN

Updated November 2026.

← All free guides