Reputation: 590
I'm trying to use Android SDK's SQLiteQueryBuilder to join two tables, let's call them t1 and t2, and query that table based on an attribute from each table, say t1.att1 and t2.att2, equaling a certain value. I'm a little confused on the syntax when it comes to the selection. Help is appreciated. Thanks!
Upvotes: 2
Views: 4255
Reputation: 3250
Here is how you can use QueryBuilder for INNER JOIN.
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
queryBuilder.setTables("t1 INNER JOIN t2 ON t1.ID=t2.ID");
queryBuilder.query(db, new String[]{"t1.att1", "t2.att2"}, "t1.att1=? AND t2.att2=?", new String[]{"value1","value2"}, null, null, null);
"value1" and "value2" are to be replaced with correct values.
Upvotes: 6
Reputation: 74134
Try with:
SELECT t1.att1, t2.att2 FROM t1
INNER JOIN t2 ON t1.ID = t2.t1ID
WHERE t1.att1 = .. AND t2.att2 = ..
* modify t1.ID and t2.t1ID to match your table's field name
Upvotes: 1