Technical Discussion :: SQL
Home > Freshers > Technical Interview Questions > SQL
61. Write a query to select the 5th highest salary from a table.
Answer:
SELECT min(salary) AS high5 FROM employee WHERE salary IN(SELECT DISTINCT TOP 5 salary FROM orders ORDER BY salary DESC)
Asked In :: TCS
SELECT min(salary) AS high5 FROM employee WHERE salary IN(SELECT DISTINCT TOP 5 salary FROM orders ORDER BY salary DESC)
---Nth record
SELECT * FROM (
SELECT SALARY, DENSE_RANK() OVER (PARTITION BY SALARY ORDER BY SALARY DESC) AS RNK,
FROM EMPLOYEE) Z
WHERE Z.RNK = 5;