I was doing some MySQL test queries, and realized that comparing a string column with 0
(as a number) gives TRUE
!
select 'string' = 0 as res; -- res = 1 (true), UNexpected! why!??!?!
however, comparing it to any other number, positive or negative, integer or decimal, gives false
as expected
(of course unless the string is the representation of the number as string)
select 'string' = -12 as res; -- res = 0 (false), expected
select 'string' = 3131.7 as res; -- res = 0 (false), expected
select '-12' = -12 as res; -- res = 1 (true), expected
Of course comparing the string with '0'
as string, gives false, as expected.
select 'string' = '0' as res; -- res = 0 (false), expected
but why does it give true for 'string' = 0
?
why is that?
0
. So0 = 0
. – lurker Feb 27 '14 at 21:13