Select*fromStudentORDERBYIdDESC;+------+---------+---------"/> Select*fromStudentORDERBYIdDESC;+------+---------+---------">

Home  >  Article  >  Database  >  How can we sort MySQL output in descending order?

How can we sort MySQL output in descending order?

WBOY
WBOYforward
2023-08-27 12:57:091519browse

我们如何按降序对 MySQL 输出进行排序?

If we want to sort the result set in descending order, we need to specify the DESC (abbreviation for DESCENDING) keyword in the ORDER BY clause.

Syntax

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

Example

In the following example, we are sorting the result set in descending order by the "Id" column.

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)

The above is the detailed content of How can we sort MySQL output in descending order?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete