Matt Good posted (a couple of weeks ago) about using ROW_NUMBER()...
> So, a query like this:
> SELECT id, name FROM my_table ORDER BY id LIMIT 10 OFFSET 20
> Would become:
> SELECT id, name FROM
> (SELECT id, name, ROW_NUMBER() OVER (ORDER BY id) AS ora_row_num
> FROM my_table ORDER BY id)
> WHERE ora_row_num > 10 AND ora_row_num <= 20
> This eliminates one level of subselects from the approach I previously
> posted. The "OVER (ORDER BY..." is required for ROW_NUMBER, so if the
> query didn't specify an ordering, then a default such as the primary key
> would need to be added.
Just to flag that unless you need to display the returned results in a
different order to that used for the limit/offset counting, I'm fairly
sure that the second " ORDER BY ID" isn't needed,
SELECT id, name FROM
(SELECT id, name, ROW_NUMBER() OVER (ORDER BY id) AS ora_row_num
WHERE ora_row_num > 10 AND ora_row_num <= 20
will do fine...
Get latest updates about Open Source Projects, Conferences and News.