Is there a clean way to limit the number of hits from an SQLite3 SELECT
statement?
For example, I might query with SELECT * FROM myTable WHERE name='Smith';
realising I could encounter thousands of hits. I'd like SQLite3 to give me say the first 10 it encounters and then terminate the query. How do I do this?
If SQLite3 does not provide this immediately, is there anything I can edit in the SQLite3 source code from which I can rebuild?
Assume I'm in an environment where I have only one thread and I'd like control back in a reasonable time.
You're looking for the
LIMIT
clause:See the SELECT syntax: there is a
LIMIT
keyword:Look at the
OFFSET
too, can be helpful for paging results. (Also these are often combined with anORDER BY
clause if you want consistent results across queries.)From the SQLite docs: