Ormlite Inner Join in five tables

Asked

Viewed 215 times

0

I want to create some JOIN in five tables like this example:

SELECT * FROM TableA AS TA
    INNER JOIN TableB AS TB ON TA.Id = TB.IdTA
    INNER JOIN TableC AS TC ON TB.IdTC = TC.Id
    INNER JOIN TableD AS TD ON TC.Id = TD.IdTC
    INNER JOIN TableE AS TE ON TD.IdTE = TE.Id
WHERE TE.Id = 30085

Note: Tableb and Tabled are tables N-M

I’m a little confused on how to do this on Android Ormlite, could someone help me with this query or provide me a step by step?

  • Primeiro:, not put *, that is, to discriminate between fields, Segundo: if Tableb and Tabled there is a junction between them and if necessary place the intermediate table with two comparisons on comparison and and comparison . Note: it would be one of the ways maybe it depends a lot on what you want to compare !!!

1 answer

1


Follows adapted response from here:

It’s gonna be something like this (adapting to your example):

// Começa a primeira query
QueryBuilder<TableA, Integer> TableAQb = TableADao.queryBuilder();
QueryBuilder<TableB, Integer> TableBQb = TableBDao.queryBuilder();
// Join entre TableA e TableB 
TableAQb.join(TableBQb);
//TERCEIRA QUERY
QueryBuilder<TableC, Integer> TableCQb =
    TableCDao.queryBuilder();
TableCQb.where().gt("mixedvalue", 100);
// join TableC
TableCQb.join(TableAQb);
List<TableC> TableCQb.query();

Following thus to the other tables.

Remembering that there is support for "raw queries", including the method Dao.queryRaw() where you can use your own query. The following documentation.

  • 1

    Ae! I managed to make for the 5 tables... Thanks!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.