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
  • 30,962
  • 25
  • 85
  • 135
Legionar
  • 7,472
  • 2
  • 41
  • 70

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
  • 44,654
  • 6
  • 52
  • 63
-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);