使用SELECT ... WHERE ID IN(...),按IN()排序结果? [英] With a SELECT...WHERE id IN (...), order results by IN()?
本文介绍了使用SELECT ... WHERE ID IN(...),按IN()排序结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
按SQL IN中的值顺序排序()条款
Possible Duplicate:
Ordering by the order of values in a SQL IN() clause
带有查询,例如:
SELECT * FROM images WHERE id IN (12,9,15,3,1)
是否可以通过IN子句的内容对结果进行排序?
is it possible to order the results by the contents of the IN clause?
我正在寻找的结果将是这样的:
The result I'm looking for would be something like:
[0] => Array
(
[id] => 12
[file_name] => foo
)
[1] => Array
(
[id] => 9
[file_name] => bar
)
[2] => Array
(
[id] => 15
[file_name] => baz
)
...
推荐答案
IN
子句定义一个集合,而数学中的集合没有顺序.
The IN
clause defines a set, and a set in mathematics has no order.
但是,通过使用
这篇关于使用SELECT ... WHERE ID IN(...),按IN()排序结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文