sql / beginner
Snippet
Sorting Rows Ascending or Descending with ORDER BY
The ORDER BY clause sorts the resulting dataset based on one or more columns. The DESC keyword sorts values in descending order from highest to lowest.
snippet.sql
sql
1
2
3
SELECT product_name, stock_quantityFROM inventoryORDER BY stock_quantity DESC;
Breakdown
1
SELECT product_name, stock_quantity
Retrieves the product name and current stock quantity.
2
FROM inventory
Specifies the 'inventory' table as the data source.
3
ORDER BY stock_quantity DESC;
Sorts the output rows by 'stock_quantity' in descending order.