Tag Archives: ASCENDING order

Order by Clause in SQL Query

Use of Order by Clause in SQL Query

Order by clause is used for sorting the data for specific column wise sequence. You can specify multiple column for sorting the output from the select query.

Syntax

Select * from table_name order by columnname [asc|desc], colname2 [asc|desc];
Note: ASCENDING (ASC) is default one if you don't specify anything

Example
Sort in DESCENDING: I want to sort and see the highest salary employee on the top of my employee tables.

Select * from employee order by salary desc;

Sort in ASCENDING Order: I want to see lowest salary employee on the first one.

select * from employee order by salary;

Sort Multiple columns: I want to sort department wise highest salary on top.

Select * from employees order by dept_no asc, salary desc;