Jose Cabrera Zuniga
Jose Cabrera Zuniga

Reputation: 2631

Retrieving "pages" with some number of rows using SQL

In PostgreSQL: To retrieve 100 rows using an SQL query we can use LIMIT 100. Is there a way to retrieve first 100 rows and later the next 100 like doing some kind of pagination? i.e.

if I do something like:

SELECT ..... LIMIT 100;

and later execute a command like:

SELECT ... LIMIT 100

I could get the next 100 rows to the previous retrieval of 100 rows and so on?

Thanks in advance

Upvotes: 0

Views: 603

Answers (1)

Yes, you need to use limit combined with offset. You can find more details here

select * from table LIMIT 100 OFFSET 100*0 --first 100
select * from table LIMIT 100 OFFSET 100*1 --second 100

Upvotes: 2

Related Questions