Advertisement

Latest Post

Sunday, 18 September 2016

How to use ORDER BY keyword in Sql

The ORDER BY keyword is used to sort the records either ascending or descending order by using ASC or DESC keyword.
The ORDER BY keyword sorts the records in ascending order by default.

Syntax:
SELECT column1, column2.. FROM your_table_name ORDER BY column_name ASC|DESC;

Example: Following is the Employee table
Id
Name
Age
Address
1
Alok Kumar Singh
30
IN
2
Tomas Paul
45
NZ
3
Cristomfer Dee
85
AU
4
Niel Macengi
55
US




Following is the ORDER BY ASC example
USE SQLCLR
GO
SELECT * FROM EMPLOYEE ORDER BY Name ASC

GO

Id
Name
Age
Address
Department
Gender
1
Alok Kumar Singh
30
IN
IT
Male
3
Cristomfer Dee
85
AU
HR
Female
4
Niel Macengi
55
US
BPO
Female
2
Tomas Paul
45
NZ
IT
Male
Following is the ORDER BY DESC example

USE SQLCLR
GO
SELECT * FROM EMPLOYEE ORDER BY Name DESC

GO

Id
Name
Age
Address
Department
Gender
2
Tomas Paul
45
NZ
IT
Male
4
Niel Macengi
55
US
BPO
Female
3
Cristomfer Dee
85
AU
HR
Female
1
Alok Kumar Singh
30
IN
IT
Male



Government Jobs