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
.
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
.
You can use order by field
WHERE id IN (8, 4, 19, 48, 15)
order by field(id,8, 4, 19, 48, 15);
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);