MySQL列= 0传回true [英] MySQL column = 0 returns true
本文介绍了MySQL列= 0传回true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
TL/DR:
我运行此查询= "Select * from test where id = 0"
,它返回所有行.
TL/DR:
I run this query = "Select * from test where id = 0"
and it returns all the rows.
这是我的下面的代码:
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.
推荐答案
您正在对文本字段进行算术比较. MySQL会将ID列中的值强制转换为数字值并将其与零进行比较. AA
,当被强制时,等于零.
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.
这篇关于MySQL列= 0传回true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文