1

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

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

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

我宁愿不必单独查询表,因为那样我就会有一堆Cursors我必须手动完成的事情,而当我只有一个时这会很困难SimpleCursorAdapter?除非一个SimpleCursorAdapter可以有几个Cursors?

谢谢。

编辑:我的表的结构:

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

基本上,这些表只是使组织分层数据结构变得更容易。我想我可以保留actual entries子表而不是子表,但添加一个前缀,并为元信息创建一个单独的表。如果我需要删除此数据集中的一个级别,似乎删除/更新结构会更加困难。

4

2 回答 2

2

您可以基于您的表创建视图,您的视图查询是您的表的联合。

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

现在您可以根据需要过滤数据以获取更多信息检查unionview

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

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

于 2011-07-12T20:42:38.530 回答
0

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.

于 2011-07-13T04:11:45.760 回答