Link to home
Start Free TrialLog in
Avatar of detox1978
detox1978Flag for United Kingdom of Great Britain and Northern Ireland

asked on

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 ?
Avatar of dqmq
dqmq
Flag of United States of America image

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

Avatar of detox1978

ASKER

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

I'm using SQL express 2005
ASKER CERTIFIED SOLUTION
Avatar of dqmq
dqmq
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks
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