Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a specific chunk of results?

Is it possible to retrieve a specific range of results? I know how to do TOP x but the result I will retrieve is WAY too big and will time out. I was hoping to be able to pick say the first 10,000 results then the next 10,000 and so on. Is this possible?

like image 942
user1076439 Avatar asked Jan 18 '23 02:01

user1076439


1 Answers

WITH Q AS (
  SELECT ROW_NUMBER() OVER (ORDER BY ...some column) AS N, ...other columns
  FROM ...some table
) SELECT * FROM Q WHERE N BETWEEN 1 AND 10000;

Read more about ROW_NUMBER() here: http://msdn.microsoft.com/en-us/library/ms186734.aspx

like image 132
Bill Karwin Avatar answered Jan 25 '23 16:01

Bill Karwin