Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find top three highest salary in emp table in oracle?

How to find top three highest salary in emp table in oracle?

like image 985
SunilRai86 Avatar asked Nov 29 '22 05:11

SunilRai86


2 Answers

SELECT  *FROM 
    (
    SELECT *FROM emp 
    ORDER BY Salary desc
    )
WHERE rownum <= 3
ORDER BY Salary ;
like image 192
Amir Avatar answered Dec 04 '22 08:12

Amir


You can try.

   SELECT * FROM 
     (
      SELECT EMPLOYEE, LAST_NAME, SALARY,
      RANK() OVER (ORDER BY SALARY DESC) EMPRANK
      FROM emp
     )
    WHERE emprank <= 3;

This will give correct output even if there are two employees with same maximun salary

like image 39
Bharat Avatar answered Dec 04 '22 07:12

Bharat