We can also sort multiple columns in different directions as given in the below query.
mysql> select name, marks, address from student order by name,
marks desc;
+---------+-------+------------------+
| name | marks | address |
+---------+-------+------------------+
| anne | 100 | downing street |
| anne | 80 | edinburgh |
| david | 98 | welling street |
| jack | 82 | victoria street |
| michael | 75 | edinburgh |
| mille | 98 | victoria street |
| steve | 100 | 5th cross street |
| steve | 75 | downing street |
+---------+-------+------------------+
8 rows in set (0.00 sec)
Here we have selected three columns name, marks and address. In this query we have sorted the column name alone in ascending order and we have additionally mentioned marks in descending order.
So if there are same names, the highest mark will be taken as the first priority. In the above example query, there are 2 anne, so the anne with highest mark will be displayed first.
|