SQL DESC Keyword
The DESC
keyword in SQL is used with the ORDER BY
clause to sort the result set of a query in descending order (from highest to lowest, or alphabetically from Z to A).
DESC: Definition and Usage
Descending order arranges the data in reverse order compared to ascending order (the default for ORDER BY
). Using DESC
is straightforward; you simply add it after the column name you're sorting by.
Syntax
Syntax
SELECT column1, column2, ...
FROM table_name
ORDER BY column_name DESC;
Example
Sorting Customer Names in Descending Order
This query selects all columns from the 'Customers' table, sorting the results alphabetically by the 'CustomerName' column in descending order (Z to A).
Syntax
SELECT * FROM Customers
ORDER BY CustomerName DESC;
Output
(The Customers table data will be displayed here, sorted alphabetically by CustomerName from Z to A)