Login

Username:

Password: 

Join us Now |  Forgot Password? | Forgot UserName?

SQL

Learn step by step



Sql Order By Clause

ORDER BY clause is used in a SELECT statement to sort results of SELECT in either ascending or descending order. Oracle by default sorts query results in ascending order.
We can use more than one column in the ORDER BY clause.
Syntax

SELECT column-list
FROM tableName
[WHERE condition]
[ORDER BY column1, column2, .. columnN] [ASC | DESC];

Consider the table Employee having following records:

FirstName LastName Email DOB Phone Salary
Jagdish Jain jagdish@yahoo.com 6/12/1988 452-345-236 15000
Ramesh Patel ramesh@gmail.com 7/12/1988 147-852-258 18000
Rahul Tanvar rahul@gmail.com 5/24/1988 233-234-234 20000
Jai Soni js@gmail.co.uk 20/12/1990 789-525-258 25000


SELECT * FROM EMPLOYEE ORDER BY FirstName, LastName;

Output

FirstName LastName Email DOB Phone Salary
Jagdish Jain jagdish@yahoo.com 6/12/1988 452-345-236 15000
Jai Soni js@gmail.co.uk 20/12/1990 789-525-258 25000
Ramesh Patel ramesh@gmail.com 7/12/1988 147-852-258 18000
Rahul Tanvar rahul@gmail.com 5/24/1988 233-234-234 20000


SELECT * FROM EMPLOYEE ORDER BY FirstName DESC;

Output

FirstName LastName Email DOB Phone Salary
Ramesh Patel ramesh@gmail.com 7/12/1988 147-852-258 18000
Rahul Tanvar rahul@gmail.com 5/24/1988 233-234-234 20000
Jagdish Jain jagdish@yahoo.com 6/12/1988 452-345-236 15000
Jai Soni js@gmail.co.uk 20/12/1990 789-525-258 25000


Related Videos