How can we 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)

Rishi Raj
Rishi Raj

I am a coder

Updated on: 20-Jun-2020

112 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements