水平联合全部
我有两个表,我需要从每个表中选择一列。 这必须在单个查询中完成。 好消息是这两列的排序方式正确,并且它们都包含相同的行数。 现在,我知道我可以通过 rowid JOIN 两个表,但它很慢,因为它必须进行比较。就我而言,这是没有必要的......我需要更像水平 UNION ALL 的东西来连接两列长度相等的列。
SQLite 3 中可能有类似的事情吗?
谢谢。
TABLE1:
| timestamp | FIELD1 | FIELD2 | ...
| 12345678 | 000000 | 000000 | ...
| 00154789 | 000000 | 000000 | ...
TABLE2:
| temperature |
| 1000000000 |
| 2000000000 |
需要选择输出
| timestamp | temperature |
| 12345678 | 1000000000 |
| 00154789 | 2000000000 |
查询:
SELECT timestamp, temperature
FROM TABLE1 INNER JOIN TABLE2 ON TABLE1.rowid = TABLE2.rowid;
在我的测试应用程序中,这大约需要 0.75 秒。当我执行两个单独的 SELECT 操作并稍后在程序中加入输出时,大约需要 0.4 秒,但这不是很方便。最快的方法(~0.23s)是将两列都放在一个表中,但这很浪费,因为我有多个版本的 TABLE2 共享相同的时间戳。
I have two tables and I need to select one column from each of them.
This must be done in a single query.
The good news is that the two columns are ordered the right way and they both contain the same number of rows.
Now, I know I could JOIN the two tables by rowid, but it is slow as it has to do that comparison. In my case it is not necessary... I need something more like horizontal UNION ALL to concatenate two columns of equal length.
Is anything like that possible in SQLite 3?
Thanks.
TABLE1:
| timestamp | FIELD1 | FIELD2 | ...
| 12345678 | 000000 | 000000 | ...
| 00154789 | 000000 | 000000 | ...
TABLE2:
| temperature |
| 1000000000 |
| 2000000000 |
REQUIRED SELECT OUTPUT
| timestamp | temperature |
| 12345678 | 1000000000 |
| 00154789 | 2000000000 |
QUERY:
SELECT timestamp, temperature
FROM TABLE1 INNER JOIN TABLE2 ON TABLE1.rowid = TABLE2.rowid;
This takes ~0.75s in my testing app. When I do two separate SELECTs and join the outputs later in my program it takes ~0.4s, but it is not very convenient. The fastest way (~0.23s) is to have both columns in one table, but it is wasteful as I have multiple versions of TABLE2 that share the same timestamps.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SQLite 支持
UNION ALL
。SQLite supports
UNION ALL
.