I have a Queue in Java which is populated form SQL with a Limit of 10, when the queue is empty I want to load the 10 next row in the table. How is this possible?. Currently I only get the same 10 rows every time the queue is empty.
Asked
Active
Viewed 152 times
-2
-
Would you like sharing table structure or any info about primary key – Nayan Srivastava Nov 24 '16 at 06:00
-
its just one table with a single PK. I just want to load 10 by 10 rows while discarding the ones that already has been showed. – brondy Nov 24 '16 at 06:14
-
1Possible duplicate of [What is the best way to paginate results in SQL Server](http://stackoverflow.com/questions/109232/what-is-the-best-way-to-paginate-results-in-sql-server) – RisingSun Nov 24 '16 at 07:57
1 Answers
0
Add one column(if you don't have in table) as sequence(1,2,3,...) and every time you pull record remember the last record's sequence and next time start by that. For example: First ten records
select * from table where sequence <11
For another 10 records
select * from table where sequence >10 and sequence <21
If your pk is string, just remember the last value of your primary key
For example: First ten records
select * from table limit 10;
for next 10 records, say last value of pk from previous fetch was "abc"
select * from table where pk>"abc" limit 10

Nayan Srivastava
- 3,655
- 3
- 27
- 49