, :
SELECT *
FROM cms_product
WHERE id IN (3, 22, 1)
ORDER BY id = 3 DESC, id = 22 DESC, id = 1 DESC;
:
CREATE TABLE cms_product (id int, value int);
INSERT INTO cms_product VALUES (1, 100);
INSERT INTO cms_product VALUES (3, 200);
INSERT INTO cms_product VALUES (22, 300);
:
+------+-------+
| id | value |
+------+-------+
| 3 | 200 |
| 22 | 300 |
| 1 | 100 |
+------+-------+
3 rows in set (0.02 sec)
UPDATE:
... ORDER BY FIELD (id, 3, 22, 1)as suggested by @Dave and @OMG Ponies returns the same results and is actually a lot neater.
source
share