简体   繁体   English

mysql WHERE子句不起作用

[英]mysql WHERE clause not working

I would like to select multiple values in where clause but it is not selecting anything. 我想在where子句中选择多个值,但未选择任何内容。

This is the select query I have: 这是我的选择查询:

'SELECT * FROM table WHERE  id IN (4, 5)  ORDER BY id desc'

what am I missing? 我想念什么?

Based on your comments, the reason that the query is failing is because the column is a varchar and you are using int values in your IN clause. 根据您的评论,查询失败的原因是因为该列是varchar并且您在IN子句中使用了int值。 MySQL does not convert the type if you quote the numbers then your query will work with varchar 如果您引用数字,MySQL不会转换类型,则您的查询将与varchar

http://dev.mysql.com/doc/refman/5.0/en/type-conversion.html http://dev.mysql.com/doc/refman/5.0/en/type-conversion.html

I would imagine your table has no data with id = 4 or id = 5. 我可以想象您的表没有ID = 4或ID = 5的数据。

Try 尝试

 SELECT * FROM table WHERE  id = 4 

Does that return anything either? 那也返回什么吗? I would bet no. 我敢打赌

为什么不只是

'SELECT * FROM table WHERE (id = '4' OR id= '5') ORDER BY id desc'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM