MySQL column = 0 returns true
mysql, sql
Solution
You're performing an arithmetic comparison on a text field. MySQL will coerce the values in your ID column to a numeric value and compare it with zero. `AA`, when coerced, equals zero.
Problem
TL/DR: I run this query = `"Select * from test where id = 0"` and it returns all the rows. Here is my code below: ``` CREATE TABLE IF NOT EXISTS `test` ( `id` varchar(20) NOT NULL, `desc` varchar(100) NOT NULL, UNIQUE KEY `id` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; INSERT INTO `test` (`id`, `desc`) VALUES ('AA', 'AA Desc'), ('BB', 'BB Desc'); SELECT count(*) FROM test WHERE id = 0 ``` In my mind it should return no rows however it returns all the rows in the table. Am I missing something? Any help and explanation would be most welcome.