有没有办法在SQLite中根据另一个查询的结果来限制查询?

huangapple go评论58阅读模式
英文:

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

SELECT/The LIMIT clause

在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/>

huangapple
  • 本文由 发表于 2023年7月12日 20:33:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76670589.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定