1

I've sorted a mySQL table by total. But it can happen that some rows have the same value. If the rows have the same value I want to sort them by another row. Is this possible?

ID | pos | name | m1 | m2 | total
1  | 1   | mike | 1  | 1  | 50
2  | 2   | alex | 16 | 12 | 14
3  | 3   | joe  | 25 | 7  | 14 
4  | 4   | jani | 7  | 24 | 14

The table is sorted by total, but if total is the same I want to sort the rows with the same value by the m2 column and change the pos by that order.

Vuistzwaan
  • 21
  • 2
  • 1
    umm, aren't you looking for `ORDER BY total DESC, m2 DESC` – Linger Sep 22 '14 at 17:31
  • This is such an easy to research question. It should have never been asked. There are many questions like this already asked: [**SQL multiple column ordering**](http://stackoverflow.com/questions/2051162/sql-multiple-column-ordering). – Linger Sep 22 '14 at 17:35

1 Answers1

0

Yes, it's possible - you can give several columns in the order by clause:

SELECT   *
FROM     my_table
ORDER BY total DESC, m2 DESC
Mureinik
  • 297,002
  • 52
  • 306
  • 350