TSQL: SELECT TOP 15 to 30 records?

Hi All,

I know it is possible to select the top 15 records via SELECT TOP 15, but how do i select the next 15.

i.e.
SELECT TOP 15 to 30 ?
LVL 2
detox1978Asked:
Who is Participating?
 
dqmqConnect With a Mentor Commented:
select * from
(select *, row_number() over(order by [ID]) seq from [MyDatabase].[dbo].[MyTable]) x
where seq between 16 and 30
0
 
dqmqCommented:
For 2005 and later, this is probably the best approach:
select * from
(select *, row_number() over(order by col1) seq from Yourtable)
where seq between 16 and 30

0
 
detox1978Author Commented:
I Get an error;

Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'where'.
select * from
(select *, row_number() over(order by [ID]) seq from [MyDatabase].[dbo].[MyTable])
where seq between 16 and 30

Open in new window

0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
detox1978Author Commented:
I'm using SQL express 2005
0
 
detox1978Author Commented:
thanks
0
 
detox1978Author Commented:
Hi,

How do i filter the results above by another select query, so that only ID that are returned from another select statment below below are returned?

many thanks
SELECT [ID] FROM [MyDatabase].[dbo].[MySecondTable]) Where [best]='5'

Open in new window

0
 
detox1978Author Commented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.