4

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

Rushi
  • 144
  • 3
  • 14

3 Answers3

9

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.

Community
  • 1
  • 1
Nevin Chen
  • 1,815
  • 16
  • 19
2

Try this:

List<ATableObj> listATableObj = ATableDao.queryRawCreate(", BTable BT 
WHERE BT.nameid = T.nameid").list();
fabrizotus
  • 2,958
  • 2
  • 21
  • 27
1

If you use greendao this works differntly:

Instead of your query you select rows from table a (or b) and if you need a field of b (or a) you call getB() (or getA()) to get the corresponding row of that table.

If you have rows in table a that have no match in table b and you have rows in table b that have no match in a and you onlly want to select everything that has matches uin both tables, you would have to do a raw query to filter the rows of a (or b).

AlexS
  • 5,295
  • 3
  • 38
  • 54