BETWEEN
is used in a WHERE
clause to select a range of data between two values.
If I am correct whether the range's endpoint are excluded or not is DBMS specific.
What I can not understand in the following:
If I have a table of values and I do the following query:
SELECT food_name
FROM health_foods
WHERE calories BETWEEN 33 AND 135;`
The query returns as results rows including calories =33 and calories =135 (i.e. range endpoints are included).
But if I do:
SELECT food_name
FROM health_foods
WHERE food_name BETWEEN 'G' AND 'O';
I do not get rows with food_name
starting with O
. I.e. the end of the range is excluded.
For the query to work as expected I type:
SELECT food_name
FROM health_foods
WHERE food_name BETWEEN 'G' AND 'P';`
My question is why is there such a difference for BETWEEN
for numbers and text data?