MySQL sort after argument in IN()

前端 未结 4 1327
刺人心
刺人心 2020-12-07 03:55

I have string containing a lot of IDs corresponding to my database. Like:

1,2,3,4,5

I then do a mySQL query to select all those rows:

4条回答
  •  旧时难觅i
    2020-12-07 04:25

    Another option, though FIELD is probably the way to go in your case:

    SELECT * FROM `table` WHERE `id` IN (2,1,3,4,5) ORDER BY `id` = 2 DESC, `id` = 1 DESC,`id` = 3 DESC, `id` = 4 DESC, `id` = 5 DESC
    

提交回复
热议问题