Android SQLite 中的多个表查询?

发布于 2024-11-19 20:35:49 字数 988 浏览 3 评论 0原文

我想知道是否有可能(应该是)在 SQLite 中同时查询多个表(一次查询多个表)。基本上我有几个具有完全相同列的表,但其中的数据只是按其所在的表组织的。我需要能够使用 SELECT 从表中获取数据(我听说UNION 可以提供帮助),它匹配一个条件,然后按其所在的表对数据进行分组。

换句话说,这样的事情可能吗?

SELECT * FROM table1,table2,table3,table4,table5,table6 WHERE day=15 GROUP BY {table}

我不想单独查询表,因为这样我就会有一堆 Cursors ,我必须手动检查它们,当我只有一个 时,这会很困难>简单光标适配器?除非一个 SimpleCursorAdapter 可以有多个 Cursor 吗?

谢谢。

编辑:我的表的结构:

Main Table - contains references to subtables in a column "tbls"
             and meta-information about the data stored in the subtables

    Subtable - contains reference to subsubtables in a column "tbls"
               and meta-information about the data stored in the
               subsubtables

        Subsubtable - contains the actual entries

基本上这些表只是使组织层次数据结构变得更容易。我想我可以不使用子子表,而是将实际条目保留在子表中,但添加前缀,并为元信息设置一个单独的表。如果我需要删除此数据集中的某个级别,那么删除/更新结构似乎会更困难。

I was wondering if it's possible (it should be) to query multiple tables simultaneously (several at once) in SQLite. Basically I have several tables that have the exact same columns, but the data in them is just organized by the table it's in. I need to be able to use SELECT to get data from the tables (I heard UNION could help), which matches a condition, then group the data by the table it's in.

In other words, would something like this be possible?

SELECT * FROM table1,table2,table3,table4,table5,table6 WHERE day=15 GROUP BY {table}

I'd rather not resort to having to query the tables individually as then I would have a bunch of Cursors that I'd have to manually go through and that would be difficult when I only have one SimpleCursorAdapter? Unless a SimpleCursorAdapter can have several Cursors?

Thanks.

EDIT: The structure of my tables:

Main Table - contains references to subtables in a column "tbls"
             and meta-information about the data stored in the subtables

    Subtable - contains reference to subsubtables in a column "tbls"
               and meta-information about the data stored in the
               subsubtables

        Subsubtable - contains the actual entries

Basically these tables just make it easier to organize the hierarchical data structure. I suppose instead of having the subsubtables, I could keep the actual entries in the subtable but add a prefix, and have a separate table for the meta-information. It just seems it would be harder to delete/update the structure if I need to remove a level in this data set.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

呆萌少年 2024-11-26 20:35:49

您可以根据表创建视图,视图的查询是表的并集。

create view test as select * from table1 union select * from table2

现在您可以根据需要过滤数据
欲了解更多信息,请检查union & 查看

http://www.w3schools.com/sql/sql_union.asp

http://www.w3schools.com/sql/sql_view.asp

You can create view based on your tables, the query of your view is union of your tables.

create view test as select * from table1 union select * from table2

now you can filter data as you want
for more info check union & view

http://www.w3schools.com/sql/sql_union.asp

http://www.w3schools.com/sql/sql_view.asp

怂人 2024-11-26 20:35:49

最后,我决定放弃许多子表,而是像蒂姆和塞缪尔建议的那样添加另一个列。它可能比用 UNION 链接 SELECT 更有效。

In the end, I decided to forgo having many subsubtables, and instead adding another column like Tim and Samuel suggested. It will probably be more efficient as well then chaining SELECTs with UNION.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文