LIMIT
can be used without an ORDER BY
clause, the results might not be deterministic without the ORDER BY
clause. This can still be useful, for example, when you want to inspect a quick snapshot of the data.
Basic LIMIT
clause examples:
ORDER BY
clause sorts the rows in the result set based on the value of the specified expression, in this case the average salary.
It’s possible to remove the GROUP BY
clause from the query and retrieve the first 5 rows of the result set without sorting the data, as shown in the example below. However, the result set will contain 5 random rows from the employees
table, as the data is not sorted.