How can we get sorted output based on multiple columns?


We can specify multiple columns in ORDER BY clause to get the sorted output based on those multiple columns. Following as an example to make this concept clearer −

mysql> Select * from Student ORDER BY Name, Address;

+------+---------+---------+-----------+
| Id   | Name    | Address | Subject   |
+------+---------+---------+-----------+
| 2    | Aarav   | Mumbai  | History   |
| 1    | Gaurav  | Delhi   | Computers |
| 15   | Harshit | Delhi   | Commerce  |
| 17   | Raman   | Shimla  | Computers |
+------+---------+---------+-----------+

4 rows in set (0.12 sec)

Updated on: 20-Jun-2020

110 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements