How to Perform the following query using Greendao ?

Rushi picture Rushi · Feb 5, 2014 · Viewed 7.8k times · Source

I have 2 tables A and B.

Table A contains names and table B contains selected names.

Now I would like to perform the following query on these tables using greendao, Please let me know if it is possible and if it is not are there any alternatives (maybe a raw query).

select * 
from A inner join B
on A.nameid = B.nameid

Also, Table A columns: id, nameid, name
and Table B columns: id, nameid, name, rating

Answer

Nevin Chen picture Nevin Chen · Feb 7, 2014

I think this might help. You can use the raw query as a fake join. And you get all you want in the Query object

Query query = ATableDao.queryBuilder().where(
new StringCondition("nameid IN " +
"(SELECT nameid FROM B_Table )").build();

Since "nameid" doesn't seems to be a unique identifier in your sample. I won't suggest to use Relations to solve this issue. If you are try to use Relations, you can find my previous answer here.