MySQL Select WHERE IN given order

前端 未结 7 1951
时光取名叫无心
时光取名叫无心 2020-12-07 20:26

I have something like

SELECT * FROM table WHERE id IN (118,17,113,23,72);

If I just do this it returns the rows in ID ascending order. Is t

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-07 21:14

    You should use "ORDER BY FIELD". So, for instance:

    SELECT * FROM table WHERE id IN (118,17,113,23,72) 
    ORDER BY FIELD(id,118,17,113,23,72)
    

提交回复
热议问题