ORDER BY Clause

Order by clause used for sort the result by one or more column. by default order by sort the result sets in ascending order. but we can add the hint to sort in ascending or descending order.

Syntax:

Select Column_List

From Table_name

Where Condition

Order by Column_name|Column_List ASC|DESC

create and insert table scripts:https://flamboyencewithsql.wordpress.com/2014/03/13/joins-in-sql-server/

Example: Here we need the result set with lowest salary on top and then second lowest and so on.

SELECT *
FROM [Work_Place]
order by Salary ASC

image

 

Now we need the result set with descending order of name and if the name are same for multiple rows then ascending order of salary.

SELECT *
FROM [Work_Place]
ORDER BY Name DESC,Salary ASC

 

image

 

Hope you will like this post on Microsoft SQL Server.

If you really like reading my blog and understood at least few thing then

please don’t forget to subscribe my blog.

Connect With me on

linkedIn | Google+ | WordPress |