我在我的sqlite數據庫中有三個表。SQLite獲取使用3個表格組合的對象列表
Categories: category_id, title
Words: word_id, title, belongs_to(foreign key, category_id)
WordImgs: wordImg_id, title, belongs_to(foreign key, words_id)
我想實現一個方法List getAllCategories。每個類別包含一個單詞列表,每個單詞包含一個wordimages列表。
我用它來加入表格,但因爲有多個值與單個值相關,所以我得到了重複的值。
SELECT categories.title, words.title, wordings.title
FROM categories
JOIN words on categories.id = words.belongs_to
JOIN wordImgs words.id = WordImgs.belongs_to
Ex。這條語句可以返回
Category,Word,wordImg
_______________
Animal Dog Dog1
Animal Dog Dog2
Animal Cat Cat1
我如何可以瀏覽我的光標,我只讓每個不同的類別,意爲我的清單1?
編輯:考慮使用三個嵌套遊標。網上沒有看到太多,有沒有更好的選擇?
檢查此鏈接:http://stackoverflow.com/questions/4957009/how-do-i-join-two-sqlite-tables-in-my-android-application – KishuDroid
「解析」意味着你想要創建你自己的數據結構,並在稍後處理它。什麼數據結構?你需要什麼? –
@CL。我試圖獲得我需要傳入我的主要活動的類別的ArrayList。也許解析不是正確的術語。 – Edward