MySQL sees 'aaa' = 0 and thinks about itself:
"I can either convert aaa to an integer, or 0 to a string."
Guess who he's walking with?
Basically, what happens is that "aaa" is converted to an integer, and since it is not a real integer, it distinguishes 0.
0 = 0, of course, true (or true == 1).
I suspect the same thing is happening with your userid column, although without knowing its values / data type, it's hard to say.
http://dev.mysql.com/doc/refman/5.0/en/type-conversion.html
source share