Click here to Skip to main content
12,077,457 members (47,518 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: SQL Server
Sir,
I want to select my nth row of my table.
like 3rd row,4th row.......
Posted 2-Jul-11 3:47am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Try:
WITH myTableWithRows AS (
    SELECT (ROW_NUMBER() OVER (ORDER BY myTable.SomeField)) as row,*
    FROM myTable)
SELECT * FROM myTableWithRows WHERE row = 3
  Permalink  
Comments
Santhosh Kumar J 16-Aug-12 3:49am
   
good one.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

you can use row_number function. Refer to following MSDN link ROW_NUMBER (Transact-SQL)[^].
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

for example, to select 5th row

SELECT TOP 1 T.* FROM
(SELECT TOP 5 * FROM DBT_Person ORDER BY AGE ASC) AS T
ORDER BY T.AGE DESC;
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

If you could, uses LINQ to SQL. That kind of stuff is much easier with Linq To SQL.

var result = (
  from m in dataContext.theTable
  select m).Skip(50).Take(1);
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 6

select * from(
select id,name,row_number() over(order by id) as 'row'  from student)as temp where row=n


Reference
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 7

There are different ways and it depends the number of rows in a table.
For more detail see
Select nth row from a table in Sql server
  Permalink  
Comments
CHill60 26-Jun-13 11:50am
   
The question is a year old and already resolved

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 | Mobile
Web02 | 2.8.160212.1 | Last Updated 2 Jul 2013
Copyright © CodeProject, 1999-2016
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