BETWEEN predicate
Syntax
BETWEEN::=
< expression to test > [NOT] BETWEEN
< begin_expression > AND < end_expression >
BETWEEN predicate specifies the inclusive range to test the expression values. The range is defined by boundary expressions with AND keyword between them. Naturally, all the expressions in BETWEEN predicate must be the same data type, as in the case of comparison predicate.
The predicate
exp1 BETWEEN exp2 AND exp3
is equal to the predicate
exp1 >= exp2 AND exp1 <= exp3
And the predicate
exp1 NOT BETWEEN exp2 AND exp3
is equal to the predicate
NOT (exp1 BETWEEN exp2 AND exp3)
If the value of the predicate exp1 BETWEEN exp2 AND exp3 is TRUE, it does not generally mean that the value of predicate exp1 BETWEEN exp3 AND exp2 is TRUE also, because the first one may be interpreted as the predicate
exp1 >= exp2 AND exp1 <= exp3
while the second one may be considered as
exp1 >= exp3 AND exp1 <= exp2
Example 5.2.3
Find model and processor speed of computers priced between and including $400 through $600:
SELECT model, speed
FROM PC
WHERE price BETWEEN 400 AND 600;
mssql
🚫
[[ error ]]
[[ column ]] |
---|
[[ value ]] |
model | speed |
---|---|
1232 | 500 |
1233 | 500 |
1232 | 500 |