Select the first 150 rows, then the next 150 and so on?
In Oracle you have the nice rownum
: it is a pseudo column. It numbers the records in a result set. The first record that meets the where criteria in a select statement is given rownum=1
, and every subsequent record meeting that same criteria increases rownum
.
SELECT a, bFROM (SELECT rownum rn, a, b from table WHERE c=some_value ORDER BY some_column)WHERE rn BETWEEN 150 AND 300;
(thanks to @Mark Bannister)
If you embed the ORDER BY clause in a subquery and place the ROWNUM condition in the top-level query, then you can force the ROWNUM condition to be applied after the ordering of the rows.