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 is a schema in sql server 2005? : Sql server database administration
What are the different types of collation sensitivity?
Explain the various types of concurrency problem. I.e. Lost or buried updates, uncommitted dependency, inconsistent analysis, phantom read?
What is sql stored procedure?
How to create hyperlink from returned sql query ?
What is sql server locking?
What is de-normalization in sql database administration? Give examples?
What is clustered index
What command would you use to create an index?
How to disable triggers using "disable trigger"?
What do you understand by integration services in sql server?
What are dml triggers and types of dml triggers?
Explain boyce and codd normal form(bcnf)?
What are null values in ms sql server?
What is difference between primary key and foreign key?