Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve data in chunks in postgresql

I want to fetch the data in chunks (using a select query) like in first attempt from 1 to 50 records and in second attempt from 51 to 100 records.

like image 880
Mak Avatar asked Feb 07 '17 04:02

Mak


1 Answers

Use LIMIT and OFFSET. The following query returns 50 records after skipping the first 50, so records 51 - 150 are returned.

SELECT fname, lname 
FROM students
ORDER BY ssn
LIMIT 100 OFFSET 50;

https://www.postgresql.org/docs/current/static/queries-limit.html

like image 175
MK. Avatar answered Sep 27 '22 22:09

MK.