FIND_IN_SET问题

时间:2010-11-30 10:38:24

标签: mysql

我有这个MySql查询:

SELECT * FROM `tbl_prods`
WHERE `id` IN ('58', '169', '166', '496', '24', '28')  
ORDER BY FIND_IN_SET(`id`, '58, 169, 166, 496, 24, 28')

结果很奇怪:

24
28
166
169
496
58

我无法弄清楚如何通过FIND_IN_SET

返回确切的顺序

我做错了什么想法?

2 个答案:

答案 0 :(得分:2)

中不应有空格
'58, 169, 166, 496, 24, 28'

将其更改为

'58,169,166,496,24,28'

答案 1 :(得分:1)

使用FIELD代替FIND_IN_SET

SELECT * FROM `tbl_prods`
WHERE `id` IN ('58', '169', '166', '496', '24', '28')  
ORDER BY FIELD(`id`, '58', '169', '166', '496', '24', '28')