Thursday, April 5, 2007

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%

{ 0 comments }