peter peter - 5 months ago 14
MySQL Question

Sorting multiple fields in MySQL

I have a table with 2 fields DATE and IMPORTANCE. Now I want to sort both these fields in DESCENDING ORDER so that the rows are ordered by IMPORTANCE for EACH DATE. For example, if sorted correct, rows should return like this:

Dec 3, 2010 - 10
Dec 3, 2010 - 10
Dec 3, 2010 - 8
Dec 3, 2010 - 7
Dec 3, 2010 - 3
Dec 3, 2010 - 1

Dec 2, 2010 - 10
Dec 2, 2010 - 9
Dec 2, 2010 - 3

Dec 1, 2010 - 8
Dec 1, 2010 - 5
Dec 1, 2010 - 5
Dec 1, 2010 - 4


Is there an efficient way of accomplishing this with only one query statement?

Answer
SELECT * FROM yourtable
ORDER BY `DATE` DESC, `IMPORTANCE` DESC