SQL multiple column ordering

Señor Reginold Francis picture Señor Reginold Francis · Jan 12, 2010 · Viewed 889.3k times · Source

I am trying to sort by multiple columns in SQL, and in different directions. column1 would be sorted descending, and column2 ascending.

How can I do this?

Answer

Ignacio Vazquez-Abrams picture Ignacio Vazquez-Abrams · Jan 12, 2010
ORDER BY column1 DESC, column2

This sorts everything by column1 (descending) first, and then by column2 (ascending, which is the default) whenever the column1 fields for two or more rows are equal.