(no title)
pascalmahe | 5 years ago
It's been some time since I've done serious work with SQL yet I remember that all paging solutions I've found (eg. top results on SO) are always platform-specific so having a platform-independent way of doing it would mean I could finally try to remember it.
forinti|5 years ago
I like to add total_rows so that I can show a "rows 10 - 19 of 81" header. You can also get the very first and last values by adding theses columns:
Alternatively, you could get the very last and very first whole rows by changing the outer where clause: And then it would be easy to have a nice header with "rows 10 - 19 of 81 (Algiers to Zimbabwe)" with very little code.bmn__|5 years ago
• https://use-the-index-luke.com/sql/partial-results/fetch-nex...
• https://use-the-index-luke.com/no-offset
e12e|5 years ago
You would normally capture such state by using cursors.
hospadar|5 years ago
As in: SELECT * FROM (SELECT *, row_number() OVER (order by <some column - primary key column would be a good choice>) as rowidx FROM your_table) as numbered WHERE rowidx > ? AND rowid < ?