The DESC keyword in SQL is used to specify that the query results are sorted in descending order, that is, from the maximum value to the minimum value. It first retrieves the data, then sorts it by the value of the specified column from large to small, and then returns the sorted results.
DESC represents descending order in SQL
In SQL, the DESC keyword is used to specify the order of database query results. descending sort. That is, sort from maximum value to minimum value.
How it works:
When DESC is used in a query, the database engine will:
Example:
The following query uses the DESC keyword to sort employees in descending order by the salary
column:
<code class="sql">SELECT * FROM employees ORDER BY salary DESC;</code>
Executing this query will return a result set with employees ordered from highest salary to lowest salary.
Note:
The above is the detailed content of Is desc in ascending or descending order in sql?. For more information, please follow other related articles on the PHP Chinese website!