【发布时间】:2011-05-10 21:16:22
【问题描述】:
当查询 db 以获取一组 id 时,mysql 不会按照指定 id 的顺序提供结果。我正在使用的查询如下:
SELECT id ,title, date FROM Table WHERE id in (7,1,5,9,3)
作为回报,提供的结果按 1、3、5、7、9 的顺序排列。
如何避免这种自动排序
【问题讨论】:
-
我曾经收到我公司一位开发人员的请求,我只是回复
Seems you have the precise information of 7,1,5,9,3, why you still need to sort it again ??? -
@ajreal 我从另一台服务器获取这些 ID。 n 我需要按相关顺序查询数据库。我不想对其进行排序,数据库以排序方式返回..我想避免排序:)
-
.. ARGGGGG...你已经在
7,1,5,9,3的ORDER中有这些ID,为什么还要重新排序??两个解决方案,query one id by id。Or use a place holder array that is your original order and fetch the results from database in whatever order, loop the place holder array and set it accordingly。你已经有了鸡,为什么还想知道鸡蛋是怎么下的?
标签: mysql sql-order-by in-operator