[英]Mysql Query Comes Back In Different Order
I have a query that I run in mysql: 我有一个在mysql中运行的查询:
SELECT *
FROM title
WHERE id
IN (
(SELECT id
FROM title
WHERE id = '71'),
(SELECT id
FROM title
WHERE id = '49'),
(SELECT id
FROM title
WHERE id = '67'),
(SELECT id
FROM title
WHERE id = '75'),
(SELECT id
FROM title
WHERE id = '74')
)
I'm expecting my records in the order given: 71, 49, 67, 75, 74 我期待我的记录顺序为:71,49,67,75,74
But what I get back is in ascending order. 但我得到的是按升序排列。
I cannot use another parameter for the search. 我无法使用其他参数进行搜索。 What I need is for my records to come back in the order given by me. 我需要的是我的记录按照我给出的顺序回来。 Is there a command that I can issue or how would I be able to work it. 是否有我可以发出的命令或我将如何工作它。
Once again, I cannot use another query parameter to sort because I don't have one. 再一次,我不能使用另一个查询参数进行排序,因为我没有。 I just need them back in the order they're being put in. 我只是按照它们被放入的顺序需要它们。
Is this even possible? 这甚至可能吗?
Thank you! 谢谢!
PS: PhP solutions only if I can sort the $result before I read the $row. PS:PhP解决方案只有在我读取$ row之前我才能对$ result进行排序。
Use FIELD
function - http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_field 使用FIELD
函数 - http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_field
Or FIND_IN_SET
- http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_find-in-set 或者FIND_IN_SET
- http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_find-in-set
/* your query begin */ ORDER BY FIELD(`id`, 71, 49, 67, 75, 74)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.