The ORDER BY command sorts the result set in ascending order by default, and to sort records in descending order, the DESC keyword is used.
The subsequent SQL statement selects all columns from the “Customers” table, sorted by the “CustomerName” column:
SELECT * FROM Customers ORDER BY CustomerName; |
The ASC command orders the data returned in ascending order. The following SQL statement selects all columns from the “Customers” table, sorted by the “CustomerName” column:
SELECT * FROM Customers ORDER BY CustomerName ASC; |
The DESC command is utilized to sort the data returned in descending order.
The following SQL statement selects all columns from the “Customers” table, sorted in descending order by the “CustomerName” column:
SELECT * FROM Customers ORDER BY CustomerName DESC; |