In Android SQLite db, how to map specific column values ​​that have the same identifier in multiple database tables?

I flushed the data in SQLite from the Json data that I get. Now my question is: I have one database with several tables. I want to link several tables using id's.These there - these are 3 tables that I created.

This is the first table in which there is a list of products,

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" + ");"; 

This is the second table in which there is a list of partners,

  private static final String DATABASE_CREATE_PARTNER = "CREATE TABLE if not exists " + "res_partner" + " (" + "_id" + " integer PRIMARY KEY autoincrement," + "phone" + "," + "mobile" + "," + "name" + ");"; 

This is the third table where we have an account row,

  private static final String DATABASE_CREATE_LINE = "CREATE TABLE if not exists " + "account_invoice_line" + " (" + "product_id" + "," + "partner_id" + ");"; 

In the third table, I have two product_id and partner_id columns, I have to match the partner_id values ​​with the column of the second column_id table , and I have to get the values ​​of the name column in it and through the values ​​in the partner_id column. I have to match the first _id table , and I have to get the values ​​in the name column.

Can someone help in creating a relationship between these tables?

+5
source share
2 answers

Try something like this:

 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 
+1
source

If you are trying to get data, you are probably looking for SQL JOINS.

enter image description here

+4
source

All Articles