ORDER BY x ASC -- same as default
ORDER BY x DESC -- highest to lowest
ORDER BY lastname, firstname -- typical name sorting; using two columns
ORDER BY submit_date DESC -- latest first
ORDER BY submit_date DESC, id ASC -- latest first, but fully specifying order.
ASC
= ASCENDING
, DESC
= DESCENDING
NULLs
come first even for DESC
.INDEX(x)
, INDEX(lastname, firstname)
, INDEX(submit_date)
may significantly improve performance.But... Mixing ASC
and DESC
, as in the last example, cannot use a composite index to benefit. Nor will INDEX(submit_date DESC, id ASC)
help -- "DESC
" is recognized syntactically in the INDEX
declaration, but ignored.