BETWEEN, IN, and Inclusive Boundaries
Boundary edge cases and how BETWEEN treats endpoints.
Why Boundaries Cost Candidates Points
Range and set filters look trivial, so interviewers weaponize the edge cases. BETWEEN includes both endpoints, IN hides a subtle NULL trap, and date ranges are where off-by-one errors silently corrupt reports.
This lesson covers exactly how BETWEEN treats its endpoints, when IN is cleaner than chained ORs, and the half-open range pattern that professionals use for dates.
BETWEEN Is Inclusive on Both Ends
col BETWEEN a AND b is shorthand for col >= a AND col <= b. Both endpoints are included.
So price BETWEEN 10 AND 20 returns rows where price is exactly 10 or exactly 20 as well as everything in between. The most common wrong answer in interviews is claiming the upper bound is excluded.
SELECT *
FROM products
WHERE price BETWEEN 10 AND 20;
-- equivalent to: price >= 10 AND price <= 20All lessons in this course
- AND/OR Precedence and Parenthesization
- BETWEEN, IN, and Inclusive Boundaries
- LIKE, Wildcards and Escaping
- Filtering on Calculated Values