Click here to Skip to main content
13,794,785 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
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 Jayaraman 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
Comments
Member 12635513 14-Jul-16 12:40pm
   
This solution helped me tremendously 2008 sql server. Top N wasn't working due to poor data quality. Thank you very much.

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 | Cookies | Terms of Service
Web04 | 2.8.181207.3 | Last Updated 2 Jul 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

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