M
M
mapleart2018-05-19 08:47:52
SQL
mapleart, 2018-05-19 08:47:52

How to execute a SQL page query if there was an offset?

Hello. I have a selection of posts from the database, they are sorted by rating and ID.
I did an Ajax upload. And I do a sample of 20 per page. And with each load I increase the page by 1.
There was a problem when new posts appeared that are higher, there is a shift by the number of new posts. If, for example, they added 2 new posts and I start loading, then the last 2 posts will be repeated.
Which is understandable. And then what is the best way to do it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Melkij, 2018-05-19
@melkij

And this is just the second reason why you should not use offset for pagination. (the first reason is the performance of offset)
Pass the sort values ​​of the last visible element of the list and ask for the continuation of the list, not offset.
https://use-the-index-luke.com/sql/partial-results...

A
Artem, 2018-05-19
@proudmore

Get the number of records in the selection before each request, and calculate pagination based on new data.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question