Easy MySQL Sorting Mistake

by damonp on April 5, 2007

in SQL

If you have a compound ORDER BY clause with a direction (ASC or DESC), make sure to specify the directions of all columns.

Correct:

ORDER BY col1 DESC, col2 DESC

Wrong:

ORDER BY col1, col2 DESC

The latter forces a filesort.

Popularity: 1%

Most Popular Posts

Damon Parker is a freelance sysadmin and web developer in Texas. He specializes in server setup, server security and high performance server configurations. Need help setting up a web server or getting a server back online after a crash or hack? Email Damon

Leave a Comment

Previous post:

Next post: