How do I filter rows that fall within an inclusive numeric range in SQLite?
Quick answer
Use price BETWEEN 10 AND 20 to include prices from 10 through 20, including both endpoints. The equivalent conditions are price >= 10 AND price <= 20. For the example prices 8, 10, 15, 20, and 22, either query returns the rows priced 10, 15, and 20; 8 and 22 are excluded. [S1]
The question, the details, the next step.
A practical checklist
Confirm the table name and numeric column you want to filter.
Write down the intended lower and upper bounds.
Use
BETWEEN lower AND upperor both>= lowerand<= upperfor an inclusive range.Check that rows equal to both endpoints are included and out-of-range rows are excluded.
Use sample values from your own table to verify the query returns the intended rows.
A few more useful answers
Does `BETWEEN` include both endpoints in SQLite?
Yes. SQLite documents x BETWEEN y AND z as equivalent to x >= y AND x <= z, so values equal to either endpoint are included. [S1]
Is `price BETWEEN 10 AND 20` different from `price >= 10 AND price <= 20`?
For this range condition, SQLite documents them as logically equivalent. Both select the example rows priced 10, 15, and 20. [S1]
Sources
References used for this guide.
- [S1] SQLite SQL Language Expressions — BETWEEN and comparison behavior sqlite.org · Checked
