Order By Clause


Prev Tutorial Next Tutorial

Order By Clause

Order By Clause are used to arrange the data either in ascending or descending order. Bydefault order by clause arrange or short the data in ascending order. To sort the records in a descending order, you can use the DESC keyword.

Note: You can apply order by clause on more than one column in the same table

Syntax

	
SELECT column_name, column_name
FROM table_name
ORDER BY column_name ASC|DESC, column_name ASC|DESC;

Example Order by

Employee table

emp_idnamesalary
101Amit24000
102Rahul34000
103Sultan54000
104Gaurav26000
105Hitesh35000

After apply join on these two table, result show like below;

Example

	
SELECT * FROM Employee
ORDER BY name;

Result after apply order by on Employee table.

emp_idnamesalary
101Amit24000
104Gaurav26000
105Hitesh35000
102Rahul34000
103Sultan54000

Order by in descending order

This is an example to sort the result in descending order by age.

Example

	
SELECT * FROM Employee
ORDER BY salary DESC;

Result after apply order by on Employee table.

emp_idnamesalary
103Sultan54000
105Hitesh35000
102Rahul34000
104Gaurav26000
101Amit24000

Prev Tutorial Next Tutorial

Advertisements




Facebook Likes

Advertisements