Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cursor JOIN with same column name

how can I access columns with the same name? I have tried doing cursor.getString(cursor.getColumnIndexOrThrow("table.column")) but it doesn't seem to work

like image 601
Christopher Francisco Avatar asked Feb 21 '14 22:02

Christopher Francisco


1 Answers

You can use aliases, i.e.

db.rawQuery("SELECT column1 AS c1 FROM table");

Then you can use:

cursor.getColumnIndex("c1");

Obviously same applies for fields from JOINs. Cheers.

EDIT

Example with join clause:

db.rawQuery("SELECT t1.columnX AS c1, t2.columnY as c2 FROM table1 t1 INNER JOIN table2 t2 ON t1.A = t2.B");

Then you can simply use the alias name regardless of the table it belongs to:

cursor.getColumnIndex("c2") should return 1.
like image 176
woot Avatar answered Sep 20 '22 23:09

woot