bloggers have encountered such a problem in development:
select * from ' user ' Whereid in (23,1,55,94)when executing a SQL similar to this one, MySQL will sort the IDs in advance and then look for them: Description: This is introduced in high-performance MySQL, in the query is actually a process of sweeping the table, in the query, the bottom is the ID in the inside of the first order from small to large optimization, and then execute in query, soIt 's a good idea to manually sort the IDs from small to large and then execute in queries, such as in (1,23,55,94), and then sort them in the order you want . But the business requires that the query results be returned in the order of the in ID (that is, the order of 23,1,55,23,94), what should be done? This statement can be done, is not very convenient:
select * from ' user ' where Find_in_set (ID, ' 23,1,55,94 ') Off -topic: There is a
non-recommended but feasible way, is to get the ID of the array after the traversal of the separate library, which will certainly affect a lot of performance ...
MySQL find_in_set (str,strlist) function use (in according to the ID of the inside sort)