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_id | order_date |
|---|---|
| 3 | 2025-03-25 |
| 17 | 2025-03-17 |
| 20 | 2025-03-12 |
| 27 | 2025-03-14 |
| 33 | 2025-03-02 |
| 34 | 2025-03-17 |
| 43 | 2025-03-09 |
| 44 | 2025-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.