Skip to main content

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;

                                                       


Comments

Popular posts from this blog

Oracle Object Oriented Concepts

An Object is a reusable application component that developers need to be aware of, rather than how it works. Object are basic entities in a system. They could represent a person, place, bank account, or any item that is handled by program. Every object consists of an attribute and one or more methods. An attribute could be any property of the object. Class:           It is a collection of attributes and functions (method) to plan the object. Object Table : ·    Object table are created by using the user defined data types. ·        In an object table each row or record is treated as an object. ·        Each row in an object table has an object Identified (OID), which is unique through out       the   database. ·       The rows or objects of an object table can be referenced by other objects with in the  database. ·    ...

About Oracle Buffer

About Oracle Buffer :- All Commands of SQL are typed at the SQL prompt. Only one SQL statement is managed in the SQL buffer. The current SQL statement replaces the previous SQL statement in the buffer. The SQL statements can be divided into different lines within the SQL buffer. Only one line i.e, the current line can be active at a time in the SQL buffer. At SQL prompt, editing is possible only in the current SQL buffer line. Every statement of SQL should be terminated using semi colon " ; ". One sql statement can contain only one semi colon. To run the previous or current SQL statement in the bufer type " / " at SQL prompt. To open the SQL editor type " ED " at SQL prompt.

Filtering and Sorting data using SQL statements

  Filtering & Sorting Data using SQL     Once you know the basics ( SELECT , FROM , WHERE ), filtering and sorting helps you get the exact rows from tables .   1. Filtering with Conditions ( AND , OR , NOT )  - Use WHERE to filter rows. - Combine with logical operators :     • AND: all conditions true      • OR: any condition true      • NOT: negate condition   - - All conditions true (AND) SELECT *  FROM employees WHERE department = 'Sales'    AND salary > 50000; -- Any condition true (OR) SELECT *  FROM employees WHERE department = 'Sales'     OR department = 'Marketing'; -- Negate condition (NOT) SELECT *  FROM employees WHERE NOT department = 'HR';   2. Pattern Matching with LIKE   - % = any sequence, _ = single char     • Names starting with 'J'      • Names with 4 letters starting with 'J'   - - N...