How do you get the fifth highest salary using self join?

Question

5th highest salary

in progress 1
TheDataMonk 3 years 3 Answers 1999 views Grand Master 1

Answers ( 3 )

  1. SELECT *
    FROM employees E1
    WHERE (SELECT COUNT(DISTINCT E2.Salary) FROM employees E2 WHERE E2.Salary >= E1.Salary) = 3

  2. Select TOP 1 salary
    FROM
    (
    Select TOP 5 salary
    From Employee
    Order BY salary DESC
    ) as E1
    ORDER BY salary ASC

  3. SELECT *
    FROM employees t1
    WHERE 5= (SELECT COUNT(DISTINCT t2.Salary) FROM employees t2 WHERE t2.Salary >= t1.Salary)

Leave an answer

Browse
Browse