“ where in ” mysql clause

前端 未结 5 773
梦毁少年i
梦毁少年i 2021-01-02 19:36

i used a mysql query where there is \"where id in (\"22,20,21\") \" but when i get the result its like array ordered in asecending order ie 20,21,20

but i need it i

5条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-02 20:31

    i think you should be able to use the FIELD keyword like so:

    SELECT * FROM table
    WHERE id in (22,20,21)
    ORDER BY FIELD(id,22,20,21);
    

    this is mysql specific, and seems magical, but it works.

提交回复
热议问题