Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

Sort MySQL Output in Descending Order



We need to specify DESC (short form for DESCENDING) keyword in ORDER BY clause if we want to sort out the result set in descending order.

Syntax

Select column1, column2,…,columN From table_name ORDER BY column1[column2,…] DESC;

Example

In the following example, we have sorted the result set by column ‘Id’ in the descending order.

mysql> Select * from Student ORDER BY Id DESC;

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

4 rows in set (0.00 sec)
Updated on: 2020-06-20T06:25:46+05:30

179 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements