I have a two tables. I want to do pagination when I call the query result is always same. Where is mistake?
select t1.id, status, category, lat, lng
from public.p t1
join public.l t2 on t1.id=t2.id and user_id=4 limit 10 OFFSET 10
I have a two tables. I want to do pagination when I call the query result is always same. Where is mistake?
select t1.id, status, category, lat, lng
from public.p t1
join public.l t2 on t1.id=t2.id and user_id=4 limit 10 OFFSET 10
Strictly speaking, without ORDER BY
Postgres is free to return any rows at all, since the order is undefined and any result is correct. (But Postgres will still apply OFFSET
, so that should even "work" without ORDER BY
.)
Retry with a (deterministic) ORDER BY
:
select t1.id, status, category, lat, lng
from public.p t1
join public.l t2 on t1.id=t2.id and user_id=4
ORDER BY ?something? -- !
limit 10
offset 10
Be that as it may, LIMIT
/ OFFSET
is typically not the best tool for pagination. See: