Click here to Skip to main content
13,143,614 members (31,491 online)
Rate this:
 
Please Sign up or sign in to vote.
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 30-Oct-13 17:59pm
Comments
Rohan Leuva 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...
Andrew Cherednik 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.. :(
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Select * From TableName Where ColumnName = (Select MAX(ColumnName) From TableName)
  Permalink  
Comments
Vikas Kottari 31-Oct-13 1:49am
   
i need to select exactly nth row (like 5th row)
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

To select the nth row without using rwo_number()& order by and cursor :

Here replace top 5 by top 'n'

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

declare @NewId bigint
 
select top 5 @NewId=eid from Tbl_Emp_Deatail
 
select * from Tbl_Emp_Detail where eid=@NewId
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web04 | 2.8.170915.1 | Last Updated 31 Oct 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100