How can we get sorted output based on multiple columns?

MySQLMySQLi Database

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)
raja
Published on 19-Feb-2018 11:01:32
Advertisements