在我之前的应用程序中,我正在从sqlite数据库中的表中检索数据。 所以我使用以下方式获取数据:
cursor = database.query("CIRCLE", new String[] { "CIRCLE_ID",
"ZONE_ID", "NAME" }, "ZONE_ID = " + id, null, null, null, "NAME");
cursor.moveToFirst();
if (!cursor.isAfterLast()) {
do {
circleLists.add(new CircleList(cursor.getInt(0), cursor
.getInt(1), cursor.getString(2)));
} while (cursor.moveToNext());
}
cursor.close();
现在我需要从一个表中检索数据,该表的id与某个其他表的id匹配,并且条件匹配来自其他表的id(在获取数据之后)。 我有SQl查询。我不知道如何在 cursor = database.query(...)
中实现此查询SQL查询是:
select d.division_id, d.name from division d, division_circle_assoc dca
where d.division_id = dca.division_id and dca.circle_id = 1
答案 0 :(得分:1)
cursor = database.rawQuery("select d.division_id, d.name from division d, division_circle_assoc dca
where d.division_id = dca.division_id and dca.circle_id = 1", null);
和
String[] columns = new String[] { KEY_D_ID, KEY_NAME};
String whereClause = KEY_D_ID + "=" + KEY_DD_ID +" AND "+ KEY_C_ID +"= 1";
Cursor cursor = mDb.query(true, DIVISION + " INNER JOIN "+ DIVISION_CIRCLE, columns, whereClause, null, null, null, null, null);