Employee Table |
OUTPUT :
SALARY
----------
77777
60000
34000
23232
Example to find the 2rd highest salary
SELECT MAX(SALARY) FROM EMPLOYEE WHERE SALARY NOT IN (SELECT MAX(SALARY) FROM EMPLOYEE);
OUTPUT :
MAX(SALARY)
-----------
60000
Example to find the 3rd highest salary
After union query is omitting first highest salary.
SELECT MAX(SALARY) FROM EMPLOYEE WHERE SALARY NOT IN (SELECT MAX(SALARY) FROM EMPLOYEE WHERE SALARY NOT IN (SELECT MAX(SALARY) FROM EMPLOYEE) UNION SELECT MAX(SALARY) FROM EMPLOYEE);
OUTPUT :
MAX(SALARY)
-----------
34000
Also Read : Oracle and MySql : Find Top 3rd highest salary row from employee table
0 comments:
Post a Comment