As seen below the two queries, we find that they both work well. Then I am confused why should we ever use BETWEEN because I have found that BETWEEN behaves differently in d
In SQL, I agree that BETWEEN
is mostly unnecessary, and can be emulated syntactically with 5000 <= salary AND salary <= 15000
. It is also limited; I often want to apply an inclusive lower bound and an exclusive upper bound: @start <= when AND when < @end
, which you can't do with BETWEEN
.
OTOH, BETWEEN is convenient if the value being tested is the result of a complex expression.
It would be nice if SQL and other languages would follows Python's lead in using proper mathematical notation: 5000 <= salary <= 15000
.
One small tip that wil make your code more readable: use < and <= in preference to > and >=.