Sorted, capped, paginated
By default the row order returned by SELECT is undefined. If order matters, you must say so with ORDER BY. Combined with LIMIT and OFFSET, this is also how you paginate.
ORDER BY col [ASC|DESC]— primary sort.- Multiple sort keys:
ORDER BY brand ASC, price DESC. - Order by an expression:
ORDER BY length(title) DESC. LIMIT N OFFSET M— return N rows starting at row M.LIMIT M, N— older shorthand; same asLIMIT N OFFSET M.
Warning: OFFSET is convenient but slow on large tables — SQLite must compute and discard the first M rows. For deep pagination, use keyset pagination:
WHERE id < last_seen_id ORDER BY id DESC LIMIT 50. Constant time regardless of how deep you've paged.