Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite3 and limiting the number of results

Tags:

c

sqlite

limit

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.

like image 878
SK9 Avatar asked Jun 13 '11 10:06

SK9


1 Answers

You're looking for the LIMIT clause:

SELECT * FROM myTable WHERE name='Smith' LIMIT 10
like image 85
patapizza Avatar answered Sep 21 '22 12:09

patapizza