The ORDER by null purpose is to force the ordering to be disabled for query results. When you check the query by explain, if you see a using Filesort in the extra column, this has a certain effect on performance, especially when group by is used, even if the specified order By,mysql you do not display is sorted by default by group field. In some cases it is not necessary to use the sort, for example, when working with the report data (after the original table data is inserted into a table for the query of the reports), you can use ORDER by NULL to cancel the sorting. Such as:
The code is as follows |
Copy Code |
INSERT into reporttable (day, clicks, revenue) Select Day, COUNT (*), SUM (revenue) from Clickorigintalbe GROUP BY day ORDER BY null |
What is the location of the null value when MySQL is sorted (order by)?
For:
At ASC, NULL is at the front, Desc at the last side