Click here to Skip to main content
15,889,398 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
can you tell me how to find 2nd highest salary without using max() or top()?
Posted
Comments
joshrduncan2012 13-Jun-13 9:07am    
Why wouldn't you use max or top?
Sagar Tajpara 13-Jun-13 9:11am    
thanks for comment.

this question is ask in interview so i don't idea for that.
if your know then helm me.
Raja Sekhar S 14-Jun-13 1:28am    
U Can Use Row_Number() For Doing That...

1 solution

SQL
1. WITH Results as
   (SELECT Row_Number() over (ORDER BY Salary DESC) as RN,* FROM tbPay)
SELECT * FROM Results WHERE RN=2

2. select PayAmount from (
select *,ROW_NUMBER()over(order by PayAmount desc)High from tbpay
)a where High=2
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900