Order By Clause

Advertisements

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

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements