Using SQLiteQueryBuilder to join two tables
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 sele开发者_JS百科ction. Help is appreciated. Thanks!
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.
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
精彩评论