Where子句在tinyint上不起作用 [英] Where clause works doesn't work on tinyint

查看:274
本文介绍了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 )

这篇关于Where子句在tinyint上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆