Sql - BETWEEN and IN
Code Life
By Pierre Marsaa
A range with BETWEEN
To keep the rows whose value falls inside a range, you could combine two comparisons with AND. SQL has a shorter way: BETWEEN.
Loading data...
These two queries return exactly the same Codémons:
↗️
Loading editor...
↶
↷
↗️
Loading editor...
↶
↷
BETWEEN is inclusive: both bounds are part of the range. Aquachu (level 15) and Florachu (level 19) are kept.
Lower bound first
Always write the smaller value first. level BETWEEN 19 AND 15 is valid SQL but returns no rows at all, because no number is both ≥ 19 and ≤ 15.
Verify