How can we sort MySQL output in descending order?

MySQLMySQLi Database

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