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 | B.tech |
| Aryan  |    165 | M.tech |
| 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.

raja
Published on 21-Feb-2018 12:57:40
Advertisements