How to get nth highest salary from tabble [Resolved]

Posted by Vikash under Sql Server on 9/22/2012 | Points: 10 | Views : 26342 | Status : [Member] | Replies : 7
Dear all
I need a SQL query that will find the nth highest salary from the database......

Regards,
Vikash Pathak



Responses

Posted by: Shameer.Ali87 on: 9/24/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
hi vikash,
try this..

SELECT TOP 1 salary FROM (
SELECT DISTINCT TOP n salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary

where n > 1 (n is always greater than one)

thanks

shameer ali shaik

Vikash, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajamani on: 9/23/2012 [Member] Starter | Points: 25

Up
0
Down
Hai sir use this query
select  Salary from (select dense_rank()over(order by salary desc)as ranking,salary from Employeetable)a where a.ranking=1


select max(Salary)as Salary from test


Vikash, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Perumal93 on: 9/23/2012 [Member] Starter | Points: 25

Up
0
Down
select max(empsalary) from employee

Vikash, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vikash on: 9/23/2012 [Member] Starter | Points: 25

Up
0
Down
Hi all
My question is that find nth highest salary not a particular highest salary......

Regards,
Vikash Pathak

Vikash, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vikash on: 9/24/2012 [Member] Starter | Points: 25

Up
0
Down
thanks shameer.............

Regards,
Vikash Pathak

Vikash, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jporter892 on: 10/27/2012 [Member] Starter | Points: 25

Up
0
Down
This is a good reference for this problem:


http://www.programmerinterview.com/index.php/database-sql/find-nth-highest-salary-sql/

Vikash, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyapriyanayak on: 1/24/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
select distinct(salary) from employee A where n=(select count(distinct(salary)) from employee B where A.salary<=B.salary)

If this post helps you mark it as answer
Thanks

Vikash, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response