Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there,

Can anybody tell me how to select nth row in sql server without using row_number() and without using order by.
Also without using cursors.(cursor can be one of the solution, but it decreases the performance when there are lacs of records.)


thanks in advance...
Posted
Comments
Thanks7872 31-Oct-13 0:35am    
without using row_number() and without using order by

Why?
Vikas Kottari 31-Oct-13 0:43am    
i need it...
chaau 31-Oct-13 0:43am    
There is a way, using TOP. Is this your homework? If yes, please research. Hint: goggle "SQL pagination using TOP"
Vikas Kottari 31-Oct-13 1:54am    
I coudn't find any.. :(

Select * From TableName Where ColumnName = (Select MAX(ColumnName) From TableName)
 
Share this answer
 
Comments
Vikas Kottari 31-Oct-13 1:49am    
i need to select exactly nth row (like 5th row)
To select the nth row without using rwo_number()& order by and cursor :

Here replace top 5 by top 'n'

SQL
declare @NewId bigint,@NewFname varchar(20),@NewLname varchar(20),@NewSalary money

select top 5 @NewId =eid,@NewFname = fname @NewLname=lname,@NewSalary=salary from Tbl_Emp_Detail

select @NewId ,@NewFname,@NewLname,@NewSalary


OR

SQL
declare @NewId bigint

select top 5 @NewId=eid from Tbl_Emp_Deatail

select * from Tbl_Emp_Detail where eid=@NewId
 
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