SQL ORDER BY

SQL ORDER BY Clause

ORDER BY Clause is used to sort the data on the basis of columns in ascending or descing order.

SQL ORDER BY Syntax

:

SELECT columnName1, columnName2, columnName3
from TableName ORDER By columnName1 , columnName2 ASC | DESC

Note : If We do not use the ASC or DESC keyword the Default order ASC is considered.

Suppose We Have The Following Data :

tableFull

ORDER BY DESC Example :

Example

SELECT * FROM `Users` ORDER BY ID Desc;

The Above Query Will Sort the result in descening order by Id. The Query Produces the result as :
sortIdDec

ORDER BY ASC Example :

Example

SELECT * FROM `Users` ORDER BY ID ASC;

The Above Query Will Sort the result in ascending order by Id. The Query Produces the result as :

sql order by sortAscid

ORDER BY Multiple Columns Example :

Example

SELECT * FROM `Users` ORDER BY Name, Email ASC;

The Above Query Will Sort the result in ascending order by Name & Email. The Query Produces the result as :

sortByMultipleCOl


Advertisements

Add Comment

📖 Read More