Returning a range of rows in DB2 (LIMIT X,Y equivalent)

3

1

Im working with DB2 and I need to be able to return a limited set of results.
Ive figured out how to return the "TOP n" results with
"FETCH FIRST n ROWS ONLY"
But I cannot figure out how to get rows from X to Y.
mySQL equivalent is LIMIT X, Y

Any ideas?

madmaze

Posted 2011-03-21T16:22:52.473

Reputation: 3 447

Answers

5

I found the solution:

SELECT * FROM (
 SELECT ROW_NUMBER() OVER() AS rownum, myLargeTable.*
 FROM myLargeTable
) AS tmp
WHERE rownum > 200000 AND rownum <= 200005;

Source

madmaze

Posted 2011-03-21T16:22:52.473

Reputation: 3 447

Nice! It has been very helpful. – None – 2012-06-29T09:39:01.200