我有桌子:
table1
------------
id | name
------------
1 | John
2 | Steeve
3 | Walter
4 | Daniel
5 | Jeremy
6 | Carmelo
...
我需要的是从表格中选择我手动输入例如id 5,3,6,1,4,2
SELECT * FROM talbe1 ORDER BY (5,3,6,1,4,2)
有可能吗? 谢谢!
答案 0 :(得分:30)
您可以使用ORDER BY
FIELD
:
SELECT * FROM talbe1 ORDER BY FIELD(id, 5,3,6,1,4,2)
答案 1 :(得分:1)
你可以试试这个:
SELECT * FROM talbe1 ORDER BY FIELD(id,'5','3','6','1','4','2')