SQLite query from multiple tables using SQLiteDatabase

android, sqlite

Solution

Try this:

Cursor mCursor = db.rawQuery("SELECT * FROM Table1, Table2 " +
                             "WHERE Table1.id = Table2.id_table1 " +
                             "GROUP BY Table1.data1", null);

Problem

I have 2 tables in my database, for example: `Table1: id (PK), data1` and `Table2: id (PK), id_table1 (FK), data2`. How can I make a query like that: ``` SELECT * FROM Table1, Table2 WHERE Table1.id = Table2.id_table1 GROUP BY Table1.data1 ``` I'm using `SQLiteDatabase` and its `query()` method. ``` Cursor mCursor = db.query(true, new String[] {"Table1","Table2"}, new String[] {"Table1.id","data1", "Table2.id", "id_table1", "data2"}, "Table1.id=Table2.id_table1", null, "Table1.data1", null,null,null); ``` But there's a problem with the second arg - it's only possible to use String, not String[] (like `new String[] {"Table1","Table2}`). What should I do to make a query from multiple tables in that way?

Original source

Related problems