Mysql – What happens if I load last 10 rows then next 10 after other rows are inserted

limitsMySQLrowselecttimestamp

What if I had a PHP script that had a pagination that loads last 10 rows then page two loaded next 10 in DESC order, but before loading next 10 on page 2, other 10 rows were added to the table?

What would happen?

And if the same 10 rows were to be loaded again, and I had a TIMESTAMP column in my table, how would I take that to my vantage to avoid that scenario?

Thanks.

Best Answer

And that is one of 3 problems with using OFFSET for "pagination".

The other two are

  • What is some rows were deleted?
  • Performance.

The solution to all of them is to "remember where you left off". Here is my blog on the issues.

Most people who use OFFSET come to this forum bemoaning poor performance. Not many have (yet) discovered the "bug" you are pointing out.