Home / SQL / Reference / Filtering

SQL BETWEEN

Test whether a value is in a range, both ends included.

Syntax

WHERE col BETWEEN low AND high

Works for numbers, text and ISO dates.

Example

Query (on the shop database used in the SQL course)

SELECT order_id, order_date
FROM orders
WHERE order_date BETWEEN '2025-03-01' AND '2025-03-31';

Result

order_idorder_date
32025-03-25
172025-03-17
202025-03-12
272025-03-14
332025-03-02
342025-03-17
432025-03-09
442025-03-22

8 rows

Good to know. For timestamps, BETWEEN '2025-03-01' AND '2025-03-31' misses times later on the 31st: use >= '2025-03-01' AND < '2025-04-01'.

Related

Learn it step by step in the free lesson WHERE: Filtering Rows, with exercises that check your queries.