Second highest salary
How can i find out second highest salary in particular database?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Dhaval PatelRank #1,023 · 1.9K reputationPosted Jan 20, 2012, 2:12 AM EST
please use this query
2nd Highest record ------------------------------------------------- SELECT * FROM TblTemp WHERE Temp_id = (SELECT min(Temp_id) FROM TblTemp WHERE Temp_id > (SELECT min(Temp_id) FROM TblTemp)) 2nd highest record ----------------------------------------------- select Temp_id from TblTemp r1 where 2=(select count(*) from TblTemp r2 where r1.Temp_id http://www.c-sharpcorner.com/Blogs/7111/how-to-get-second-highest-and-lowest-record-in-sql-server.aspxJignesh TrivediRank #16 · 50.3K reputationPosted Jan 22, 2012, 6:20 PM EST
try this
select * from(
SELECT empId, salary,
ROW_NUMBER()OVER(PARTITION BY salary ORDER BY salary desc ) as RowNum
from ExaminationOptions) A
where A.RowNum =n
using the above query u can find n number of highest salary.
hope this help.
Prabhu RajaRank #861 · 2.6K reputationPosted Jan 22, 2012, 6:58 PM EST
Try this out , Hope it will help you.
DECLARE @N Int
SET @N = 2
If this post helps you, then mark as "Correct Answer". Thank You
Sonakshi SinghRank #624 · 3.8K reputationPosted Jan 22, 2012, 7:07 PM EST
Satyapriya NayakRank #47 · 31.5K reputationPosted Jan 22, 2012, 8:11 PM EST
For 2nd highest salary
Here n=2
select distinct(salary) from employee A where 2=(select count(distinct(salary)) from employee B where A.salary<=B.salary)
Thanks