MySQL ORDER BY IN() [英] MySQL ORDER BY IN()
本文介绍了MySQL ORDER BY IN()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有ID编号的PHP数组.这些号码已经订购.
I have a PHP array with numbers of ID's in it. These numbers are already ordered.
现在,我想通过IN()方法获取结果,以获取所有ID.
Now i would like to get my result via the IN() method, to get all of the ID's.
但是,这些ID的顺序应与IN方法中的顺序相同.
However, these ID's should be ordered like in the IN method.
例如:
IN(4,7,3,8,9)
应给出如下结果:
4 - Article 4
7 - Article 7
3 - Article 3
8 - Article 8
9 - Article 9
有什么建议吗?也许有一个功能可以做到这一点?
Any suggestions? Maybe there is a function to do this?
谢谢!
推荐答案
I think you may be looking for function FIELD -- while normally thought of as a string function, it works fine for numbers, too!
ORDER BY FIELD(field_name, 3,2,5,7,8,1)
这篇关于MySQL ORDER BY IN()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文