0

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
Hermes
  • 452
  • 10
  • 24

1 Answers1

0

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:

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228