Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
desikankannan
Posting Yak Master
152 Posts |
Posted - 2008-01-25 : 04:38:37
|
Hi,iam new to this forum i was asked a question in an interviewhow we can get second highest salary and person nameHow to retrive second highest salary queryDesikankannan |
|
sunil
Constraint Violating Yak Guru
282 Posts |
Posted - 2008-01-25 : 05:01:52
|
SELECT s.SalaryFROM(SELECT DISTINCT Salary,DENSE_RANK() OVER (ORDER BY Salary DESC) AS rnkFROM table1WHERE Salary IS NOT NULL) AS sWHERE rnk = 2Just replace rnk with whatever highest salary you want.Also, please try to google first for your queries. If you would have put "second highest salary sql server", you would have got your answer and many more ways to achieve it. The reply that I am posting is from following link:http://www.eggheadcafe.com/software/aspnet/29735786/third-highest-salary.aspx |
 |
|
raaj
Posting Yak Master
129 Posts |
Posted - 2008-01-25 : 09:17:40
|
u can try in this way also :select min(salary) from table_namewhere salary in (select top 2 salary from table_name order by salary desc) |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|