how to find nth highest salary
Answer Posted / himanshu
Just replace the N with required number:
SELECT empid, empname, empsalary FROM emp e
WHERE (SELECT COUNT(DISTINCT(e2.empsalary))
FROM emp e2
WHERE e2.empsalary >=
e.empsalary ) = N
ex: 4th highest
SELECT empid, empname, empsalary FROM emp e
WHERE (SELECT COUNT(DISTINCT(e2.empsalary))
FROM emp e2
WHERE e2.empsalary >=
e.empsalary ) = 4
Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What do you mean by sql server agent?
What is scrollable cursor?
Why we use trigger in sql server with example?
In case you have filters in your report, when filters will be applied in cached report instance?
Explain the xml support sql server extends?
can you implement data mining in SSRS?
Can we insert data if clustered index is disabled?
What is @@rowcount in sql?
can a database be shrunk with users active? : Sql server administration
Give the query of getting last two records from the table in SQL SERVER?
Do you know what is difference between index seek vs. Index scan?
How do you run a trace?
Can a unique index be created on a column, which contains null?
what are cursors? : Sql server database administration
What is the server name for sql management studio?