HOW TO USE SQL ORDER BY CLAUSE

ORDER BY IN SQL

ORDER BY CLAUSE

ORDER BY keyword sorts the records in ascending order by default. To sort the records in descending order, use the DESC keyword.

Syntax to sort the records in ascending order:

SELECT ColumnName1,…,ColumnNameN

FROM <TableName>

ORDER BY <ColumnName> ASC;   

Syntax to sort the records in descending order:

SELECT ColumnName1,…,ColumnNameN

FROM <TableName> 

ORDER BY <ColumnName>DESC;   

Syntax to sort the records in ascending order without using ASC keyword:

SELECT ColumnName1,…,ColumnNameN

FROM <TableName >

ORDER BY <ColumnName>;   


Leave a Reply

Your email address will not be published. Required fields are marked *