Search This Blog

Friday, September 7, 2012

ORDER BY

Used to arrange the select statement output in ASCENDING or DESCENDING order
  • Supports with all types of data
  • it is only for display purpose
Syntax:-
Select * from  order by   
If we want to sort in descending order then specify “ desc “
Select * from 
order by desc
By default oracle will use ascending order.
Ex:
SQL> select * from EMP order by ename;
 
 
Here we can see that ‘ENAME’ came in ‘ASCENDING ORDER’.
Ex:
SQL> select * from EMP order by ename desc;
 
 
Here we can see that ‘ENAME’ came in ‘DESCENDING ORDER’.
SQL>select *from EMP where order by sal;
 
 
Here we can see ‘SAL’ came in ‘ASCENDING ORDER’.
SQL>select *from EMP where order by sal desc;
 
 
Here we can see that ‘SAL’ came in DESCENDING ORDER.
SQL>select empno,ename,job,sal from emp order by 2;
 
 
Here 2 represents second column. So, data will display according to ename in ascending order.

No comments:

Post a Comment