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) UNIONSELECT MAX(SALARY) FROM EMPLOYEE);
OUTPUT :
MAX(SALARY)
-----------
34000
No comments:
Post a Comment