我掙扎了幾sqlite的疑問在我的Android項目結合起來。合併多個SQLite的查詢
我得到我ItemTable的所有元素與此調用
String sql = "SELECT n.*, p.ParentID "
+ "FROM NameTable n, "
+ " ItemTable p "
+ "WHERE p.itemID = n.OwnerID "
+ "COLLATE NOCASE";
然後得到他們的每一個父母與這兩個查詢之一:
if (aItem.parentID > 0) {
sql = "SELECT n.*, p.ParentID, f.FamilyID "
+ "FROM NameTable n, "
+ " FamilyTable f, "
+ " ItemTable p "
+ "WHERE f.FamilyID = '" + aItem.parentID + "' "
+ " AND p.ItemID = n.OwnerID "
+ " AND (p.ItemID = f.MotherID OR p.itemID = f.FatherID) "
+ " AND n.IsPrimary = 1 ";
} else {
sql = "SELECT n.*, p.ItemID, f.FamilyID "
+ "FROM NameTable n, "
+ " FamilyTable f, "
+ " ChildTable c, "
+ " ItemTable p "
+ "WHERE c.ChildID = '" + aItem.ItemID + "' "
+ " AND p.ItemID = n.OwnerID "
+ " AND c.FamilyID = f.FamilyID "
+ " AND (p.ItemID = f.MotherID OR p.ItemID = f.FatherID) "
+ " AND n.IsPrimary = 1 ";
}
有什麼辦法,我可以將這三個查詢和邏輯合併爲一個?我猜想,結合呼叫會更快,但我不知道如何將它們結合起來,也不能確定如何,如果我沒有將它們合併讀取行。我真的可以使用一些建議和幫助。
方法有很多,但如果你把數據庫架構和查詢的目的是一個祕密,沒有人可以幫助你。 – 2013-03-17 10:15:57