MySQL query result set is sorted according to the specified field value order

If the mysql query result is not given the specified order by, then mysql will sort the result set according to the primary key order (innodb engine), then the final sort may not be the sort result you want.

For example, I want to query the database according to the mongoId collection passed from the front end and return the same sorted result collection, such as (M3, M5, M4), and their corresponding primary key order is (M4, M3, M5). If the query result is sorted without order by in the query statement, the result will become the primary key order (M4, M3, M5).

Just like the picture above, the final result is sorted by VId. Then if you want to return the results in the order of (M3, M5, M4), you need to use the self-sorting field order by field ( value ,str1,str2,str3) .

sql is as follows:

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325131405&siteId=291194637