2

In my application previously I was retrieving data from table which is in sqlite database. So I was using following way to get the data:

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();

Now I need to retrieve data from one table whose id is matched by id of some other table and where condition match id(after getting data) from some other table. I have the SQl query. I don't know how to implement this query in cursor = database.query(...)

The SQL query is:

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
1

1 Answer 1

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);

and

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);
Sign up to request clarification or add additional context in comments.

1 Comment

I know we can use rawQuery... but is there any way to use database.query(...) to retrieve data...???

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.