You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@empire-db.apache.org by "Becker, Joel" <jo...@essvote.com> on 2012/06/11 19:18:50 UTC
join same table twice in a query
Hello. In a select query, how do I join the same table twice on two
different fields?
For example:
cmd.select(...);
cmd.join(db.PERSON.TRIP_ID, db.TRIP);
cmd.join(db.TRIP.START_CITY_ID, db.CITY.ID);
cmd.join(db.TRIP.END_CITY_ID, db.CITY.ID);
Then I want to get the start CITY.NAME and the end CITY.NAME.
-Joel
re: join same table twice in a query
Posted by Rainer Döbele <do...@esteam.de>.
Correct (Thanks T-Rex)
You need two difference instances of a table to be able to address them individually in your query.
You can either do that in your database definition:
public final Employees EMPLOYEES = new Employees(this);
public final Employees EMPLOYEES_2 = new Employees(this);
or alternatively use the clone method:
Employees EMPLOYEES_2 = (Employees)EMPLOYEES.clone();
Then in your query just treat them as if they were two different tables.
Rainer
Von: T-Rex [mailto:trex521@googlemail.com]
Gesendet: Montag, 11. Juni 2012 20:30
An: user@empire-db.apache.org
Betreff: Re: join same table twice in a query
Hello Joel,
as far as I know you have to create a second instance of your table if you want to make a second join on the same column.
If i am correct you have to do something like this:
cmd.join(db.TRIP.START_CITY_ID, CITY_instance1.ID <http://db.city.id/> );
cmd.join(db.TRIP.END_CITY_ID, CITY_instance2.ID <http://db.city.id/> );
Can you try it and tell us if that works?
Pascal
2012/6/11 Becker, Joel <jo...@essvote.com>
Hello. In a select query, how do I join the same table twice on two different fields?
For example:
cmd.select(...);
cmd.join(db.PERSON.TRIP_ID, db.TRIP);
cmd.join(db.TRIP.START_CITY_ID, db.CITY.ID);
cmd.join(db.TRIP.END_CITY_ID, db.CITY.ID);
Then I want to get the start CITY.NAME and the end CITY.NAME.
-Joel
Re: join same table twice in a query
Posted by T-Rex <tr...@googlemail.com>.
Hello Joel,
as far as I know you have to create a second instance of your table if you
want to make a second join on the same column.
If i am correct you have to do something like this:
cmd.join(db.TRIP.START_CITY_ID, CITY_instance1.ID <http://db.city.id/>);****
cmd.join(db.TRIP.END_CITY_ID, CITY_instance2.ID <http://db.city.id/>);
Can you try it and tell us if that works?
Pascal
2012/6/11 Becker, Joel <jo...@essvote.com>
> Hello. In a select query, how do I join the same table twice on two
> different fields?****
>
> ** **
>
> For example:****
>
> ** **
>
> cmd.select(…);****
>
> cmd.join(db.PERSON.TRIP_ID, db.TRIP);****
>
> cmd.join(db.TRIP.START_CITY_ID, db.CITY.ID);****
>
> cmd.join(db.TRIP.END_CITY_ID, db.CITY.ID);****
>
> ** **
>
> Then I want to get the start CITY.NAME and the end CITY.NAME.****
>
> ****
>
> -Joel****
>
> ** **
>