Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

ORDER BY

ORDER BY

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:

Example

SELECT * FROM Customers
ORDER BY CustomerName; 

ASC

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:

Example

SELECT * FROM Customers
ORDER BY CustomerName ASC

DESC

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:

Example

SELECT * FROM Customers
ORDER BY CustomerName DESC