Monday 29 May 2017

DBMS ORDER BY clause ~ GNIITHELP

Order By Clause

Order by clause is used with Select statement for arranging retrieved data in sorted order. The Order by clause by default sort data in ascending order. To sort data in descending order DESC keyword is used with Order by clause.

Syntax of Order By

SELECT column-list|* from table-name order by asc|desc; 


Example using Order by

Consider the following Emp table,
eidnameagesalary
401Anu229000
402Shane298000
403Rohan346000
404Scott4410000
405Tiger358000
SELECT * from Emp order by salary; 
The above query will return result in ascending order of the salary.
eidnameagesalary
403Rohan346000
402Shane298000
405Tiger358000
401Anu229000
404Scott4410000

Example of Order by DESC

Consider the Emp table described above,
SELECT * from Emp order by salary DESC;
The above query will return result in descending order of the salary.
eidnameagesalary
404Scott4410000
401Anu229000
405Tiger358000
402Shane298000
403Rohan346000

No comments:

Post a Comment