We’ve already discussed using the ORDER BY clause with subqueries. You can also, however, use the
ORDER BY
clause with sorting results of one of the columns. Actually, this is most common way to use this clause.
Sometimes such queries require using temporary tables or filesort, and a regular
EXPLAIN
clause provides this information. But it doesn’t show if this job is needed for
ORDER BY
or for optimizing another part of the query.
For example, if we take a pretty simple query (
select distinct last_name from employees order by last_name asc
) and run
EXPLAIN
on it, we can see that both the …
[Read more]