How to use the order by clause in sql?
Example:
-- Trying to retrieve customers without ordering them
SELECT name FROM customers;
Solution:
-- Correctly retrieving customers and ordering them by age in descending order
SELECT name FROM customers ORDER BY age DESC;
The ORDER BY keyword is used in SQL to sort the result set by one or more columns. Here, we order the customers based on their age in descending order.