Testing beyond limits!

Search This Blog

Monday, April 14, 2014

Retrieve 'n' th highest salary from an employee table

Recently in an interview I was asked a question to write a query for retrieving 3rd highest salary from a table employee.
In case you too need the solution here it is:

SELECT salary FROM (SELECT salary, rownum rnum FROM
(SELECT * FROM employee ORDER BY salary DESC)WH ERE rounum <= nWHERE rnum>=n;

Here 'n' is the nth highest salary you need to retrieve from the employee table.