英文:
Is there a way to limit a query based on the result of another in sqlite?
问题
我正在寻找与这个问题类似的东西,但适用于sqlite3
。这可能吗?
英文:
I'm searching for something similar to this question, but for sqlite3
. Is this possible?
答案1
得分: 1
在LIMIT子句中可以使用任何标量表达式,只要它评估为整数或可以无损转换为整数的值...
您可以直接在LIMIT
子句中使用子查询的整数结果:
SELECT *
FROM table1
ORDER BY id
LIMIT (SELECT COUNT(*) FROM table2);
查看一个简化的演示。
英文:
From SELECT/The LIMIT clause:
> Any scalar expression may be used in the LIMIT clause, so long as it
> evaluates to an integer or a value that can be losslessly converted to
> an integer...
You can use directly the integer result of a subquery in the LIMIT
clause:
SELECT *
FROM table1
ORDER BY id
LIMIT (SELECT COUNT(*) FROM table2);
See a simplified demo.<br/>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论