Mysql
 sql >> Database >  >> RDS >> Mysql

Come recuperare le righe nell'ordine richiesto in mysql

Puoi provare questo:

SELECT cat_title
FROM table1
WHERE cat_id IN(21,10,25,4)
ORDER BY (cat_id = 21) DESC, (cat_id = 10) DESC, (cat_id = 25) DESC, (cat_id = 4) DESC;

o

SELECT cat_title
FROM table1
WHERE cat_id IN(21,10,25,4)
ORDER BY FIND_IN_SET(cat_id, ('21,10,25,4'));