RSS Feed

SQL - Finding Nth Highest Salary

How to find the Nth highest salary from a table in SQL?

Solution:
Query to find the Nth highest salary:

SELECT DISTINCT  (a.sal) 
FROM EMP A 
WHERE &N = (SELECT COUNT (DISTINCT (b.sal)) 
            FROM EMP B 
            WHERE a.sal<=b.sal)


Replace &N in the above query with 2 if you want to know the second highest salary and so on.