I'm struggling to combine a few sqlite queries in my android project.
I'm getting all the elements of my ItemTable with this call
String sql = "SELECT n.*, p.ParentID "
+ "FROM NameTable n, "
+ " ItemTable p "
+ "WHERE p.itemID = n.OwnerID "
+ "COLLATE NOCASE";
Then get each of their parents with one of these two queries:
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 ";
}
Is there any way I can combine these three queries and the logic into one? I would imagine that combining the calls would be faster, but I'm not sure how to combine them, and also not sure how to read the rows if I did combine them. I could really use some advice and assistance.