Click here to Skip to main content
15,880,543 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
can anybody help me how to get nth highest salary without using top
Posted

Which database system?

If SQL Server, look into ROW_NUMBER() or ORDER BY with FETCH { FIRST | NEXT } { integer_constant | fetch_row_count_expression } { ROW | ROWS } ONLY
https://msdn.microsoft.com/en-us/library/ms188385.aspx[^]
 
Share this answer
 
v2
Without using the Loop you can get it in many ways, but it depend upon the sql Server version

Row_Number 2008+[^]
OFFSET FETCH 2012+[^]
Common Table Expression 2008+[^]

Sub_Query etc.

Try:
C#
;with cte as
{
select top 5 * from Table_Name order by Column_Name Asc
)
select top 1 * from cte order by Column_Name Desc 
 
Share this answer
 
v2

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