SQL
Power Unleashed
Last Updated 09th March 1998
Getting the nth highest salary
This SQL will find the employee with the nth highest salary
from the 'employee' table-
emp_id |
Integer |
salary |
decimal(12,0) |
Select emp_id, salary
From employee a
Where
(Select
Count(*)
From employee
b
Where b.salary
> a.salary) = (n-1)
To list all the employees in the 'top - n salary bracket' use-
Select emp_id, salary
From employee a
Where
(Select
Count(*)
From employee
b
Where b.salary
> a.salary) <= (n-1)
Credit: Raj at LES
Back
to my HomePage