How do I filter rows between two dates in SQL?
SELECT * FROM data
WHERE order_date BETWEEN '2025-01-10' AND '2025-01-20'
ORDER BY order_date;
Run this query in QueryLocal →
When dates are stored as text in `YYYY-MM-DD` format, plain string comparison sorts and compares them correctly because that format is lexicographically ordered the same as chronologically ordered. `BETWEEN 'a' AND 'b'` is inclusive on both ends, equivalent to `order_date >= 'a' AND order_date <= 'b'`.
A table named data with columns: order_id (integer), customer (text), country (text), category (text), quantity (integer), unit_price (real), order_date (text, YYYY-MM-DD).