Why “SELECT … WHERE id=1=0” returns all rows except one with id=1?

  • A+
Category:Languages

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| +----+-------+ 

 


The reason is that the logic should be being evaluated as:

WHERE (id = 1) = 0 

This is equivalent to:

WHERE (id = 1) "is false" 

Or:

WHERE id <> 1 

Try running these examples:

select 1=1=0, 1=2=3, 1=1=0 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: