- I have 2 tables
resources
resource_votes_aggregate which stores the number of likes per resource_id
I want to paginate through resources in descending order of their title using seek/keyset pagination
Without Pagination, this is what you get
- I want the results in batches of 5 as I am paginating 5 results at a time
My PAGE 1 query worked without issues using the query below
SELECT
r.resource_id,
title,
COALESCE(likes, 0) AS likes
FROM
resources r
LEFT JOIN
resource_votes_aggregate a
ON r.resource_id = a.resource_id
WHERE
category_id = 1
ORDER BY
title DESC,
resource_id DESC LIMIT 5;
- How do I get the next page using keyset/seek pagination?
My attempt
SELECT
r.resource_id,
title,
COALESCE(likes, 0) AS likes
FROM
resources r
LEFT JOIN
resource_votes_aggregate a
ON r.resource_id = a.resource_id
WHERE
category_id = 1
AND
(
likes,
title
)
< (586, 'Zatoichi Meets Yojimbo (Zatôichi to Yôjinbô) (Zatôichi 20)')
ORDER BY
title DESC,
resource_id DESC LIMIT 5;
Incorrect Results
UPDATE 1
I have created a FIDDLE HERE which loads 20 results? How to paginate this in batches of 5 using seek pagination?