我从Json数据中将数据转储到sqlite中.现在我的问题是我有一个包含多个表的数据库我希望使用id来关联多个表.这些是我创建的3个表.
这是我们有产品清单的第一张表,
private static final String DATABASE_CREATE_PRODUCT =
"CREATE TABLE if not exists " + "product_template" + " (" +
"_id" + " integer PRIMARY KEY autoincrement," +
"name" + "," +
"list_price" + "," +
"create_date" + "," +
"default_code" + "," +
"ean13" + "," +
"image_new" + "," +
"image_variant" +
");";
这是我们有合作伙伴名单的第二张表,
private static final String DATABASE_CREATE_PARTNER =
"CREATE TABLE if not exists " + "res_partner" + " (" +
"_id" + " integer PRIMARY KEY autoincrement," +
"phone" + "," +
"mobile" + "," +
"name" +
");";
这是我们有账户线的第三张表,
private static final String DATABASE_CREATE_LINE =
"CREATE TABLE if not exists " + "account_invoice_line" + " (" +
"product_id" + "," +
"partner_id" +
");";
在第三个表中,我有两列product_id和partner_id,我应该匹配partner_id与第二个表列_id的值,我应该在其中获取name列的值,并通过列partner_id中的值我应该与第一个表_id匹配,我应该得到值在名称列中.
任何人都可以帮助创建这些表之间的关系吗?
解决方法:
尝试这样的事情:
SELECT t1.name prod_name, t2.name part_name from product_template t1, res_partner t2, account_invoice_line t3 where t3.product_id = t1.id and t3.partner_id = t2.id