ASCending DESCending

suggest change
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.

Mixing ASC and DESC, as in the last example, cannot use a composite index before MySQL 8.0. From MySQL 8.0, an index declared with the same directions, such as INDEX(submit_date DESC, id ASC), can be used. Before 8.0, DESC in an index declaration was accepted and ignored.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents