first 3 highest salary from emp table in oracle.

Discussions

EJB design: first 3 highest salary from emp table in oracle.

  1. hi, can anyone plz tell me how to find the only first 3 highest salary from emp table in oracle.

    I have used order by desc but it shows all the sal of all employees

    regards
    Sukhbir
  2. You could use the rownum variable to list the top three

    Select xxxx
    from yyy
    where
    zzz = ??? and
    rownum
  3. select top 3 sal from employee order by sal
  4. Reply[ Go to top ]

    Sukhbir,

    You should use rownum, however, remember, that rownum doesn't work with order properly, so you should use subquery:

    select * from (select * from emp order by sal) where rownum<3

    That should work.

    Alex
  5. select * from (select distinct salary from ran1  order by salary desc)where rownum<=3;

        SALARY
    ----------
         20000
         14000
         12000