(D) SQL ORDER BY Clause
(D) SQL ORDER BY Clause
o The ORDER BY clause in SQL will help us to sort the records based on the specific column
of a table.
o Using the ORDER BY clause, we can sort the records in ascending or descending order as
per our requirement. The records will be sorted in ascending order whenever the ASC
keyword is used with ORDER by clause. DESC keyword will sort the records in descending
order.
o If no keyword is specified after the column based on which we have to sort the
records, in that case, the sorting will be done by default in the ascending order.
Write a query to sort the records in the ascending order of the customer
names stored in the customers table.
Write a query to sort the records in the ascending order of the addresses
stored in the customers table.
Here in a SELECT query, an ORDER BY clause is applied to the 'Address' column to sort the records.
No keyword is used after the ORDER BY clause. Hence, the records, by default, will be sorted in
ascending order.
Example 3:
Write a query to sort the records in the descending order of the customer
salary stored in the customers table.
Write a query to sort the records in the descending order of the customer
age stored in the customers table.