In SQL, use the ORDER BY clause to sort in descending order, and its syntax is ORDER BY
DESC. Multiple columns can be sorted in descending order and added to the clause in the order of column names, such as ORDER BY DESC, DESC.
How to sort descending order in SQL
In SQL, use the ORDER BY
clause Sort query results in descending order. The syntax of the ORDER BY
clause is as follows:
<code class="sql">ORDER BY <column_name> DESC</code>
Where:
is the name of the column to be sorted.
means descending order.
Example
To sort thename column in the
students table in descending order, you can use the following query :
<code class="sql">SELECT * FROM students ORDER BY name DESC;</code>
name column in descending order.
Descending sorting of multiple columns
You can also sort multiple columns in descending order. To do this, add the column names to theORDER BY clause in the following order:
<code class="sql">ORDER BY <column_name1> DESC, <column_name2> DESC, ...</code>
Example
To comparestudents To sort the
name column and the
age column in the table in descending order, you can use the following query:
<code class="sql">SELECT * FROM students ORDER BY name DESC, age DESC;</code>
nameColumn descending order, then the result set sorted by
age column descending order.
The above is the detailed content of How to descend in sql. For more information, please follow other related articles on the PHP Chinese website!