P
P
POLOVIN2019-01-23 18:30:01
MySQL
POLOVIN, 2019-01-23 18:30:01

Page selection starting from a certain element?

It is necessary to make a page-by-page selection from mysql by the column in which the date is stored in the timestamp format.
If you do this:
'SELECT * FROM files ORDER BY date DESC LIMIT 0, 20'
'SELECT * FROM files ORDER BY date DESC LIMIT 20, 20', etc.,
then the next fetch after updating the database will display the data already received earlier.
And if so:
'SELECT * from files ORDER BY date < 1548068216 DESC LIMIT 20,20'
there is a possibility that the database contains data with an identical date and then part of the data, on the contrary, will not be received.
How to write a query to return these 20 elements but starting from the element with a certain id ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
POLOVIN, 2019-01-24
@POLOVIN

kind person helped on stackoverflow

R
Rsa97, 2019-01-23
@Rsa97

Within one second sort by id

WHERE `date` <= :prevDate AND `id` < :prevId
ORDER BY `date` DESC, `id` DESC

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question