How can I change the default sort order of MySQL tables?

As we know that when we use ORDER BY Clause, the default sort order of MySQL table is ascending, start with the smallest value. We can change this default order by using DESC keyword along with ORDER BY Clause. The following example will clarify this concept −

>mysql> Select * from STUDENT ORDER BY Name DESC;
| Name   | RollNo | Grade  |
| Gaurav |    100 | |
| Aryan  |    165 | |
| Aarav  |    150 | M.SC   |
3 rows in set (0.00 sec)

We can see that after using the keyword DESC the default order has been changed from ascending to descending.

Updated on: 21-Feb-2020


Kickstart Your Career

Get certified by completing the course

Get Started