我的查询
select * from product where productId in(25,36,40,1,50);
结果显示如下
`productId ProductName Qty Price`
-------------------------------------
`1 | namesome | 5 | 25.00`
`25 | namesome | 5 | 35.00`
`36 | namesome | 5 | 35.00`
`40 | namesome | 5 | 35.00`
`50 | namesome | 5 | 35.00`
我没有使用任何 order by
子句,但是它自动应用了 productId
的顺序,
我需要没有任何排序的结果,如下所示
`productId ProductName Qty Price`
-------------------------------------
`25 | namesome | 5 | 25.00`
`36 | namesome | 5 | 35.00`
`40 | namesome | 5 | 35.00`
`1 | namesome | 5 | 35.00`
`50 | namesome | 5 | 35.00`
我怎样才能做到这一点?
数据库引擎:MyIsam,排序规则:utf8_general_ci,productId
最佳答案
select *
from product
where productId in(25,36,40,1,50)
order by find_in_set(productId, '25,36,40,1,50');
See this SQLFiddle
关于mysql - 使用 IN() 选择查询且不进行任何排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13657859/