I’ve just attempted my first Inner Join, Select statement in Android and it doesn’t work. The database it’s self has no relationships set up as I don’t know how to do that yet if possible at all. I am able to select from both tables individually, but the following select doesn’t work.
return(getReadableDatabase().rawQuery("SELECT _id, FacilityName FROM Facility INNER JOIN BeachFacility ON Facility.FacilityID = BeachFacility.FacilityFK WHERE BeachFK=?", args));
Is there something I’m missing or more I need to know to do this?
Cheers,
Mike.
If anyone is interested.
The database model I came up with for this exercise was to leave all the primary key names at _id and the middle table i.e.. beaches_facilities table that sits between beaches and facilities, I renamed the primary key field in there to BF_id.
This way I can still reference the main tables with the _id key in other queries and it works beautifully.
Thanks all!
If you are following Android’s _id convention, the assumption would be that both of your tables have that column.
With that being said, the query above would probably throw a “Ambiguous column _id” error. Qualify your tables as Yaqub mentioned and you should be ok.
Also, always test out your queries in the sqlite client first. Save yourself the trouble.