Here's my query:
SELECT * FROM article WHERE id IN (300, 400, 100)
But it always orders the articles the same, by id.
So I would get out for the above:
id
100
300
400
Is there a way to get the results out in the order that they were requested in the IN statement? eg.
id
300
400
100
You can try something like this. Use the FIELD() function.
SELECT * FROM article
WHERE id IN (300, 400, 100)
ORDER BY FIELD(id, 300, 400, 100);
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