Range Finder: The BETWEEN Operator
The Quarterly Review
It was time for the financial report. *"I need a list of all transactions that happened between October 1st and December 31st,"* the CFO requested. *"Oh, and only if they were between $100 and $500."*
I was tempted to use `>=` and `<=`, but those "Double Logic" filters are easy to misread.
The Quest: The Boundary Logic
SQL provides a dedicated keyword for ranges: `BETWEEN`. It is **inclusive**, meaning it includes the start and end values themselves.
The Implementation: The Double Target
Instead of writing `price >= 100 AND price <= 500`, we write:
-- Filtering for price and dates in ranges
SELECT *
FROM orders
WHERE price BETWEEN 100 AND 500
AND order_date BETWEEN '2025-10-01' AND '2025-12-31';
Why it's safer
The "Oops" Moment
I once forgot that `BETWEEN` includes the exact timestamps. If a transaction happened at exactly midnight on the end date, it might get skipped if I didn't handle the time format correctly.
**Pro Tip**: When using `BETWEEN` with dates, it's often safer to use `'2025-12-31 23:59:59'` to ensure you catch the very last minute of the year.
The Victory
The CFO got his report with zero "Missing" end-of-year transactions. Range logic is the backbone of all financial reporting, and `BETWEEN` is the professional's choice for precision.
Your Task for Today
Filter a numerical column using `BETWEEN`. Then, try to use it on a date column and see how it handles the boundaries.
*Day 12: Text Cleanup—Fundamental String Functions.*