Why the following query:
SELECT * FROM myTable WHERE id=1=0
returns all rows from myTable
except one which has id=1
?
myTable
content:
+----+-------+
| id | value |
+----+-------+
| 1 | dog |
| 2 | cat |
| 3 | parrot|
+----+-------+
Now run: SELECT * FROM myTable WHERE id=1=0
Output:
+----+-------+
| id | value |
+----+-------+
| 2 | cat |
| 3 | parrot|
+----+-------+
WHERE (id = 1) = 0
... When ID = 1 it ends up as 1 which <> 0.0
equalsfalse
.id = 1
is an expression that results in a boolean value (true, false or null), so MySQL expects a boolean on the right side of=
. It finds0
, which it interprets asfalse
.