views:

53

answers:

1

I would like to implement or use functionality that allows stepping through a Table in SQLite.

If I have a Table Products that has 100k rows, I would like to retrive perhaps 10k rows at a time. Somthing similar to how a webpage would list data and have a < Previous .. Next > link to walk through the data.

Are there select statements that can make this simple? I see and have tried using the ROWID in conjunction with LIMIT which seems ok if not ordering the data.

// This seems works if not ordering.

SELECT * FROM Products WHERE ROWID BETWEEN x AND y;
+3  A: 

Are you looking for offset and limit? SQLite supports these. You can then use order by, which SQLite also supports.

EDIT: To elaborate, you can do something like:

Select * from Products order by name limit 10000 offset 10000;

This fetches the second 10k page from the table, sorted by name. Watch out for performance issues when dealing with limit/offset and order by.

SB
You'd use this query in your code, and make the value passed into offset a parameterized value that you increment by 10k for each chunk of records you need.
sheepsimulator
Thank you this is exactly what I was looking for.
galford13x
Thanks for fixing my error sheep
SB