SQL ORDER BY DESC

The DESC keyword in SQL is used to sort the result set in descending order. It sorts data from highest to lowest. You can use DESC to organize numbers from largest to smallest, text in reverse alphabetical order, or dates from most recent to oldest.
This is useful when you want to display top-performing products, the most recent transactions, or the highest values first in your results.

Example

This query will sort the products in descending order based on the Price column (largest to smallest).

Code Example


-- Sorting products by price in descending order using DESC
SELECT Product, Price
FROM Orders
ORDER BY Price DESC;
            

Output

Product Price
Laptop 1200.00
Phone 800.00
Tablet 600.00

Explanation

- The query selects the Product and Price columns from the Orders table.
- The ORDER BY Price DESC sorts the data in descending order by the Price column, showing the highest-priced items first.

This type of sorting is useful when you want to highlight the most expensive or latest items in your result set.