In short utilising AS to give the duplicate columns names specific column names.
For example instead of
SELECT * FROM Aisles LEFT JOIN Shops ON aisleshoplink = shops._id
you could use
SELECT aisles._id AS aisles_id, aisleshoplink, aislename, shops._id AS shop_id, shopname FROM aisles LEFT JOIN shops ON aisleshoplink = shops._id
However, you will then not get an _id column as may be required (e.g. for a CursorAdapter). The list of columns may also be quite extensive and you want most. So you could use
SELECT *, aisles._id AS aisles_id, shops._id AS shops_id FROM aisles LEFT JOIN shops ON aisleshoplink = shops._id
This has the disadvantage that again there are two _id columns, so using the id returned, say in an OnItemClick
listener may not be as expected.
So perhaps using the first, with all columns specifically provided including specifically including the appropriate _id should be used :-
SELECT aisle._id, aisles._id AS aisles_id, aisleshoplink, aislename, shops._id AS shop_id, shopname FROM aisles LEFT JOIN shops ON aisleshoplink = shops._id
To use the above via the SQLite query
method could be:-
String query_tables = "aisles LEFT JOIN shops ON aisleshoplink = shops._id";
String[] columns = {
"aisle._id".
"aisles._id AS aisles_id",
"aisleshoplink",
"aislename",
"shops._id AS shop_id",
"shopname"
};
Cursor mycursor = db.query(query_tables,
columns,null,null,null,null,null
);
The resultant cursor would have columns :-
- _id
- aisles_id
- aisleshoplink
- aislename
- shops_id
- shopname