1

I am stuck with one scenario in which I need to do complex query to get cursor. Don't know It is possible or not. Scenario is : There are three tables in database.

 Table         Columns  
Table-1    _id, name, number, ....  
Table-2    _id, table1_id, col1, col2, ....  
Table-3    _id, table2_id, col1, col2, ....

In these tables, when any record is inserted in table 2, corresponding table1 id is inserted in that record. Same for table2 id is inserted with table 3 record.

I want cursor for CursorAdapter to display list view of Table-3 data.

Cursor cursor = getContentResolver().query(TABLE_3_NAME, null, null, null, null);

Now need to add selection and selection args of Table-1 in this query.
Is it possible in Android?

1
  • do you want to display data of table 3 in listview and that from get data from table 1 when select particular data from listview Commented May 3, 2016 at 5:18

2 Answers 2

1

You can use raw query to fetch from various tables. One example would be as below.

 Cursor mCursor = db.rawQuery("SELECT * FROM Table-1, Table-3 " +
                         "WHERE Table1.id = <Whatever selection args you want> " +
                         "GROUP BY Table1.id", null);

This is just an example. You will have to change it as per your requirement.

Sign up to request clarification or add additional context in comments.

Comments

1

You can write a SQL selection query (i.e. normal way) and you can execute using rawQuery() method.

For example:

Cursor cursor = db.rawQuery(selectQuery, null);

Comments

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.