I have something like:
SELECT * FROM table WHERE id IN (118, 17, 113, 23, 72);
It returns the rows ordered by ID, ascending. Is there a way to get back the rows in the order specified in the IN
clause?
You should use "ORDER BY FIELD". So, for instance:
SELECT * FROM table WHERE id IN (118,17,113,23,72) ORDER BY FIELD(id,118,17,113,23,72)
Try using FIND_IN_SET
:
SELECT * FROM table WHERE id IN (118,17,113,23,72) ORDER BY FIND_IN_SET(id, '118,17,113,23,72');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With