Skip to main content

One post tagged with "order by null"

View All Tags

Explicitly Disable Sorting of Result Set

· 2 min read
PawSQL Team
Optimize your SQL Queries by Clicks!

Copyright © 2024 PawSQL

Problem Definition

In earlier versions of MySQL, GROUP BY would default to sorting by the grouping fields even without an ORDER BY clause. This could cause unnecessary file sorting which impacts SQL query performance. Adding ORDER BY NULL forces disabling sorting on the result set.

For example in the following:

SELECT l_orderkey, sum(l_quantity) 
FROM lineitem
GROUP BY l_orderkey;