ASCending DESCending
suggest changeORDER 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 forDESC
.- In the above examples,
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.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents