mysql custom sort

前端 未结 4 1748
遥遥无期
遥遥无期 2020-12-01 09:32

I have a query like this: SELECT * FROM table WHERE id IN (2,4,1,5,3);

However, when I print it out, it\'s automatically sorted 1,2,3,4,5. How can we ma

4条回答
  •  不思量自难忘°
    2020-12-01 10:05

    SELECT * FROM table WHERE id IN (2,4,1,5,3) ORDER BY FIELD(id,2,4,1,5,3);
    

    Source: http://imthi.com/blog/programming/mysql-order-by-field-custom-field-sorting.php

提交回复
热议问题