Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 retrieving n-th record

Author  Topic 

misterraj
Yak Posting Veteran

94 Posts

Posted - 2009-07-06 : 00:59:00
I have a query which will retrieve some 1000 records,

select * from table1 where column = condition

I also need to retriev nth record from it, for example if the user passes 5, i need 5th record from this query. if the user passes 100 i need 100th record.

is there any way to retrieve the nth record from a single query
something like this

select * from table1 where rownumber =n?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-06 : 01:00:42
[code]
select *
from (
select *, row_no = row_number() over (order by somecol)
from table1
) t
where t.row_no = @n
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-07-06 : 01:44:23
see this link
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/find-nth-maximum-value.aspx
Go to Top of Page
   

- Advertisement -