Order By Clause

  • This clause in a select statement arranges the data on a specified column in ascending or in descending order.
  • This clause will work after the execution of select statement.
  • By default it arranges the data in ascending order.
  • In order to arrange the data in descending order , an option called DESC is used.
  • Data is arranged in order over a required column for temporary.
  • Order by clause can be specified with one or more columns.


      Examples :-

        Display empno, ename and salary of all the employees arranging salaries in ascending order.

        Ans : Select empno, ename, sal from emp order by sal;

        Display ename, job, salary, deptno, commission, and hiredate of all those employees who are working as CLERK, SALESMAN and they have been hired in the year 81 and they don’t earn any commission. Arrange the data in ascending order of salary.

        Ans : Select ename, job, sal, deptno , comm, hiredate from emp
          Where job IN(‘CLERK’ , ‘SALESMAN’) AND
          Hiredate LIKE ‘%81’ AND
          Comm IS NULL
          Order by sal;

        Display ename, job, sal of all the employees arranging job in ascending order and salary in descending order.

        Ans : Select ename, job, sal from emp
          Order by job, sal desc;

        Display ename, job, sal of all those employees arranging job and sal in ascending order.

        Ans : Select ename, job, sal from emp
          Order by job, sal;

                                                       


No comments:

Post a Comment

Infolinks In Text Ads