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 different databases as found in w3school
SELECT *
FROM employees
WHERE salary BETWEEN 5000 AND 15000;
SELECT *
FROM employees
WHERE salary >= 5000
AND salary <= 15000;
BETWEENcan help to avoid unnecessary reevaluation of the expression:t_sourceis just a dummy table with1,000,000records.Of course this can be worked around using a subquery, but in
MySQLit’s less efficient.And of course,
BETWEENis more readable. It takes3times to use it in a query to remember the syntax forever.In
SQL ServerandMySQL,LIKEagainst a constant with non-leading'%'is also a shorthand for a pair of>=and<:However,
LIKEsyntax is more legible.