avoid Sorting by the MYSQL IN Keyword

后端 未结 4 517
伪装坚强ぢ
伪装坚强ぢ 2020-12-19 14:34

When querying the db for a set of ids, mysql doesnot provide the results in the order by which the ids were specified. The query i am using is the following:



        
4条回答
  •  清歌不尽
    2020-12-19 15:27

    There is no auto-sorting or default sorting going on. The sorting you're seeing is most likely the natural sorting of rows within the table, ie. the order they were inserted. If you want the results sorted in some other way, specify it using an ORDER BY clause. There is no way in SQL to specify that a sort order should follow the ordering of items in an IN clause.

提交回复
热议问题