Select ID from a where ID in (111, 1,111) order by instr ('11, ', ID ))
In this case, there will be errors, which need to be solved through the following methods
There are two methods:
1. select ID from a where ID in (111, 111) order by instr (',', Concat (',', ID ,',')) note that you need to construct more numbers.
2. (recommended) Select * From 'mytable' where 'id' in (111, 111) order by field ('id) // It seems that the result is not correct when I test this statement.
YesArticleNote:
Field (STR, str1, str2, str3 ,...)
Returns the index (position) of str in the str1, str2, str3,... list. returns 0 if STR is not found.
Sorting Process: Find the ID of the selected records in the field list, and return the location based on the position.
This usage will lead to using filesort, which is a very inefficient sorting method. Unless the data changes frequently or has a long cache, we do not recommend that you sort the data in this way.
The author suggests thatProgramCodeIt is sorted by itself, but I did not find any performance bottleneck during the test.