SQLite3 和限制结果数量
有没有一种干净的方法来限制 SQLite3 SELECT 语句的命中次数?
例如,我可能会使用 SELECT * FROM myTable WHERE name='Smith'; 进行查询,因为我意识到可能会遇到数千次点击。我希望 SQLite3 告诉我它遇到的前 10 个,然后终止查询。我该怎么做?
如果 SQLite3 没有立即提供此功能,我可以在 SQLite3 源代码中编辑哪些内容来重建?
假设我处于一个只有一个线程的环境中,并且我希望在合理的时间内恢复控制权。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您正在寻找
LIMIT
子句:You're looking for the
LIMIT
clause:请参阅 SELECT 语法:有一个
LIMIT
关键字:查看
OFFSET
也有助于分页结果。 (此外,如果您希望跨查询获得一致的结果,这些通常与 ORDER BY 子句结合使用。)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.)来自 SQLite 文档:
From the SQLite docs: