SQL
5 min read
BEGINNER
BETWEEN and IN
Quick AnswerBETWEEN tests an inclusive interval. IN tests membership in a list of values. Both reduce repetition in filtering conditions.
Core idea
BETWEEN tests an inclusive interval. IN tests membership in a list of values. Both reduce repetition in filtering conditions.
Minimal example
sql
SELECT id FROM products WHERE price_cents BETWEEN 100 AND 350 ORDER BY id;Expected SQLite rows:
text
124How it works
For non-NULL values, x BETWEEN a AND b means x >= a AND x <= b. IN (1, 3) matches either value. Do not use NOT IN with a nullable list without understanding UNKNOWN; a later chapter covers NULL logic.
Practical example
sql
SELECT id, name FROM products WHERE id IN (1, 3) ORDER BY id;Expected SQLite rows:
text
1 | Notebook3 | BagCommon mistake and practice
BETWEEN includes both endpoints. Find prices from 100 through 150 cents and verify that both boundary products appear.