Where子句在tinyint上不起作用

问题描述:

我的MySQL查询有问题.我有一张表,其中的列"read"之一的值默认为"1",并且由phpmyadmin而不是bool自动设置为tinyint(1).

there is a problem with my MySQL query. I have a table with one of the columns "read" where the values are "1" by default and is automatically set to tinyint(1) by phpmyadmin instead of bool.

当我执行查询时:

SELECT * FROM book WHERE read = '1'

它给出了一个错误.

但是当我执行此查询时:

But when I perform this query:

SELECT * FROM book WHERE id = '77'

很好.除了可能无法以这种方式搜索tinyint之外,我没有发现任何问题.有人可以帮忙吗?我曾在Google上旅行,但没有找到答案.

It is fine. I don't see any problem except that maybe tinyint cannot be searched that way. Can someone please help? I've travelled across google but found no answers.

只需删除引号

因为它是tinyint,所以您不应使用引号(将它们用于字符串,字符或日期)

as it is tinyint you should not use quote (use them for strings or characters or dates)

select * from `table_name` where `read`=1;

如果它不起作用,则可以按照Ilion所述进行投射(很好)

if it doesn't work then you can do casting as mentioned by Ilion ( it's good )