java - Using multiple tables to get data SQLitedatabase -
i have 3 tables in database: category, words, , wordimgs. i'm trying implement listgetallcategories , problem need retrieve data 3 tables in order this. suppose join 3 tables? not quite sure how accomplish this.
each category contains name , arraylist of words. each word contains name arraylist of images.
statements used create tables:
public void oncreate(sqlitedatabase db) { final string sql_create_category_table = "create table " + categories_table + " (" + _id + " integer primary key autoincrement," + title + " text not null " + ");"; final string sql_create_words_table = "create table " + words_table + " (" + _id + " integer primary key autoincrement," + title + " text not null, " + belongs_to + " integer not null, " + "foreign key (" + belongs_to + ") references " + categories_table + " (" + _id + ")" + ");"; final string sql_create_wordimg_table = "create table " + wordimgs_table + " (" + _id + " " + "integer primary key autoincrement," + title + " text not null, " + belongs_to + " integer not null, " + "foreign key (" + belongs_to + ") references " + words_table + " (" + _id + ")" + ");"; db.execsql(sql_create_category_table); db.execsql(sql_create_words_table); db.execsql(sql_create_wordimg_table); }
you can join 3 tables this:
select * categories_table c join words_table w on c.id = w.belongs_to join wordimgs_table wi on w.id = wi.belongs_to
Comments
Post a Comment