Saturday, 23 November 2019 16:59

what is SQL Order by clause and how to use it

Written by 
Rate this item
(0 votes)

The ORDER BY clause used to sort the sql query results in 

ascending or in descending order

 FYI ORDER BY keyword always sorts the result in ascending order. 

But if you want to sort the records in descending order, 

then use this DESC keyword.

 

For example, suppose there is a customers table with lots of columns ,

the following SQL statement selects all customers data from  

"Customers" table which are sorted by the Age column value :

 

SELECT * FROM Customers ORDER BY Age;

If we want to sort in descending order then we just put DESC like this : 

SELECT * FROM Customers ORDER BY Age DESC;

 

It's possible to sort using multiple columns, like this way where 

it sorts descending by the Country and  ascending by the CustName column : 

SELECT * FROM Customers ORDER BY Country DESC, CustName ASC;

 

Don't forget to like & share it. 

Connect with me if you want to learn - https://www.fiverr.com/mitsol

Read 162 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.
Login to post comments