I have the following query
SELECT * FROM table WHERE id IN (5,4,3,1,6)
and i want to retrieve the elements in the order specified in the "id in.." meaning it should return:
5 .... 4 .... 3 .... 1 .... 6 ....
Any ideas how to do that?
Use FIELD():
SELECT * FROM table WHERE id IN (5,4,3,1,6) ORDER BY FIELD(id, 5,4,3,1,6);
2.1m questions
2.1m answers
60 comments
57.0k users