Reputation: 150
I need two tables for my search. and i used inner join to get this two. But this two different table has some same column names(which i need). how can i differentiate this columns.
Here is what i did.
final String MY_QUERY = "SELECT * FROM Products p INNER JOIN Categories c ON p.CategoryID=c._id"; Cursor cursor = db.rawQuery(MY_QUERY, null);
and i m using this cursor in my CursorAdapter to set my listview cell fields.
prodName.setText(cursor.getString(cursor.getColumnIndex("Name")));
prodCategory.setText(cursor.getString(cursor.getColumnIndex("Name")));
As you see these are suppose to different values from different tables. But they show same value(name) because my inner join has this field 2 times and i dont know how can i separete them.
Upvotes: 1
Views: 1194
Reputation: 39641
Instead of *
name the columns you are querying and use an alias, for example:
SELECT p.name as pname, c.name as cname, ...
and then
prodName.setText(cursor.getString(cursor.getColumnIndex("pname")));
prodCategory.setText(cursor.getString(cursor.getColumnIndex("cname")));
Upvotes: 2