name salary ----- ----- mohan 500 ram 1000 dinesh 5000 hareesh 6000 mallu 7500 manju 7500 praveen 10000 hari 10000
How would I find the nth-highest salary from the aforementioned table using Oracle?
Advertisement
Answer
you can use something like this.. this is what i have tested and then pasted here
SELECT * FROM tblname WHERE salary = (SELECT * FROM (SELECT * FROM (SELECT * FROM (SELECT DISTINCT( salary ) FROM tblname ORDER BY salary DESC) A WHERE rownum <= nth) B ORDER BY salary ASC) C WHERE rownum <= 1)
in place of ‘tblname’ give your table name and then in place nth give your desired nth highest salary that you want
you can see in the screen shot that it is working.