开发者

FIND_IN_SET problem

I have this MySql query:

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')

the result is weird:

24
28
166
169
496
58

I can't figure out how to return the exact order by my FIND_IN_SET

any ideas where I am doing wrong?


You should not have spaces in

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

Change it to

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


Use FIELD instead of 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')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜