status = 'test'
results in true or false which equals 1 or 0 in MySQL.
BETWEEN 2 AND 'test'
translates to BETWEEN 2 AND 0
in MySQL.
x BETWEEN a AND b
translates to x >= a AND x <= b
.
So the condition is never met:
1 >= 2 AND 1 <= 0 => false
2 >= 2 AND 2 <= 0 => false
The query should never return any row.
CORRECTION: It shows that MySQL doesn't Interpret
WHERE status = 'test' BETWEEN 2 AND 'test'
as
WHERE (status = 'test') BETWEEN 2 AND 'test'
but as
WHERE status = ('test' BETWEEN 2 AND 'test')
which I consider a flaw. (EDIT: I looked it up; it is a flaw. The comparision operator =
should have precedence over BETWEEN
: https://dev.mysql.com/doc/refman/5.7/en/operator-precedence.html.)
Anyway:
('test' BETWEEN 2 AND 'test')
is always false, which is 0 in MySQL.
- If status is a string column, then status converted to integer results in 0 for most strings. Only if the string starts with an integer that integer is converted to number. E.g. '123ABC' results in 123.
- If status is a numeric column it is not converted.
- If status is a boolean column it gets converted to 0 for false and 1 for true.
- So some rows get returned, others not.