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
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 :
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 :
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 :
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 :
Advertisements
Add Comment
📖 Read More
- 1. SQL - UPDATE
- 2. SQL - DELETE
- 3. SQL - Like
- 4. SQL In Operator
- 5. SQL Between