简体   繁体   English

如何在一个iOS应用程序查询中从单个sqlite数据库的多个表中获取数据?

[英]How to get data from multiple tables from single sqlite database in one query for iOS application?

I'm working on an application where i need to get the details from sqlite database. 我正在开发一个需要从sqlite数据库获取详细信息的应用程序。
The database consists of multiple tables. 该数据库由多个表组成。 I need to pass a global id to fetch the records related to one another in the database from multiple tables (like a relational database) 我需要传递一个全局ID,以从多个表(如关系数据库)中获取数据库中彼此相关的记录。

I don't know how to fetch the related records from database and display it in a master detail table controller. 我不知道如何从数据库中获取相关记录并将其显示在主明细表控制器中。

Please provide with possible solution 请提供可能的解决方案

For example lets say you got Table1 with fields x1, x2, x3, a . 例如,假设您获得了具有字段x1,x2,x3,a的 Table1 say you got Table2 contains your id(global id) g , and a foreign key relation with Table1's field ' a ' and its field z1, z2, z3. 假设您获得了Table2,其中包含您的id(全局id) g ,以及与Table1的字段“ a ”及其字段z1,z2,z3的外键关系。

Table1--->x1, x2, x3, a
Table2--->g, z1, z2, z3, a

Now we are gonna fetch the contents of Table1 based on the id 'g' of Table2. 现在,我们将基于表2的ID“ g”获取表1的内容。

SELECT t1.x1, t2.x2, t3.x3, t3.a FROM Table t1, Table t2 WHERE t1.a = t2.a AND t2.g = g

In "t2.g = g" 'g' is the global id you are holding. 在“ t2.g = g”中,“ g”是您持有的全局ID。 good luck in learning joints. 学习关节好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM