简体   繁体   中英

mysql WHERE clause not working

I would like to select multiple values in where clause but it is not selecting anything.

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. MySQL does not convert the type if you quote the numbers then your query will work with varchar

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.

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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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