I need to select users from my database with the "IN" statement like:
SELECT *
FROM users
WHERE user_id IN ("20,24,23,26,27,28,25")
...this works but i need exactly this order (20,24,23,26,27,28,25) for my output. PHP orders the ids by DESC or ASC ... how can i solve this problem?
just use FIELD()
in the ORDER BY
clause
ORDER BY FIELD(user_id, 20, 24, 23, 26, 27, 28, 25) ASC
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