0

I need to order results in the same order, as they are in IN(...) clausule. How to do this? For example:

SELECT id, name, desc FROM my_table WHERE id IN (8, 4, 19, 48, 15)

So I need to have results ordered in this order 8, 4, 19, 48, 15.

Dharman
  • 26,923
  • 21
  • 73
  • 125
Legionar
  • 7,254
  • 2
  • 37
  • 67

2 Answers2

0

You can use order by field

WHERE id IN (8, 4, 19, 48, 15)
order by field(id,8, 4, 19, 48, 15);
Abhik Chakraborty
  • 43,914
  • 5
  • 48
  • 61
-1

mySQL:

You need to append ORDER BY FIELD(id,7,5,3,1)

SELECT id, name, desc FROM my_table WHERE id IN (7,5,3,1) ORDER BY FIELD(id,7,5,3,1);