SQL ORDER BY CLAUSE

ORDER BY
The ORDER BY clause is used in a SELECT statement to sort results either in ascending or descending order. 

Oracle sorts query results in ascending order by default.

SYNTAX

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


Example for Order by clause | Order by examples

The following query sorts the employees according to ascending order of salaries.
            select * from emp order by sal;

The following query sorts the employees according to descending order of salaries.
            select * from emp order by sal desc;

The following query sorts the employees according to ascending order of names.
            select * from emp order by ename;

The following query first sorts the employees according to ascending order of names.If names are equal then sorts employees on descending order of salaries.
            select * from emp order by ename, sal desc;

You can also specify the positions instead of column names. Like in the following query,which shows employees according to ascending order of their names.
            select * from emp order by 2;

The following query first sorts the employees according to ascending order of salaries.
If salaries are equal then sorts employees on ascending order of names

            select * from emp order by 3, 2;