SQL BETWEEN Operator: Filtering Ranges
Range filters are cleaner when the lower and upper bounds are written together.
BETWEEN
checks whether a value is inside a range. It is often clearer than writing
one condition for the lower bound and another condition for the upper bound.
The important detail:
BETWEEN
is inclusive. A value equal to the start or end of the range is included.
That is why a month range written with
BETWEEN
works on
order_date, which holds plain dates. On a column that also stores a time, the last
day's later hours would fall outside the range. Lesson 7.1 shows the
half-open range that avoids that.
select column_one, column_two
from table_name
where column_name between lower_value and upper_value Schema · Garden Shop Table · orders 6 columns · 24 rows
One row per order. Unshipped orders have a null shipped_date.
Show the order id, order date, and status for orders placed during March 2024.
Run your query to inspect the result.
Expected answer
- Columns: order_id, order_date, status.
- Rows: 4 March orders.
- Dates should run from 2024-03-02 through 2024-03-30.
Related
Comparisons, AND/OR, IN, BETWEEN, and LIKE.
SELECT, WHERE, ORDER BY, and LIMIT at a glance.
Debug filters that match nothing.
Nested SELECTs, IN, EXISTS, and correlation.
UNION, UNION ALL, INTERSECT, and EXCEPT.
A stray NULL drops every row. Use NOT EXISTS.