Descending sorting can be achieved in SQL by using the DESC keyword. Syntax: SELECT column_name(s) FROM table_name ORDER BY column_name DESC; For example, to sort employees in descending order by the salary column: SELECT name, salary FROM employees ORDER BY salary DESC.

Descending sort in SQL
In SQL, the method to implement descending sort is very simple, you can use KeywordDESC.
Syntax:
SELECT column_name(s) FROM table_name ORDER BY column_name DESC;
Example:
Suppose we have the following table:
CREATE TABLE employees ( id INT NOT NULL AUTO_INCREMENT, name VARCHAR(255) NOT NULL, salary INT NOT NULL, PRIMARY KEY (id) );
The following query Will return all employees in descending order by columnsalary:
SELECT name, salary FROM employees ORDER BY salary DESC;
Notes:
Key Words can only be used inORDER BYclauses.after each column name. For example:SELECT name, salary FROM employees ORDER BY salary DESC, name DESC;
salarycolumn in descending order, and if thesalaryare equal, then by thename# in descending order ## Column to sort the results.
The above is the detailed content of How to write descending order in sql. For more information, please follow other related articles on the PHP Chinese website!
Commonly used permutation and combination formulas
Common tools for software testing
How to download flv file
linux view system information
How many years do you have to pay for medical insurance to enjoy lifelong medical insurance?
Which is more worth learning, c language or python?
Talent assessment tools
cad2012 serial number and key collection