You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Cristian Zoicas <zo...@medialab.sissa.it> on 2003/12/11 13:48:34 UTC
How to create a join ?
Hello all
I've tried to figure out how to use the Criteria class in
order to obtain a statement like
SELECT
*
FROM
T1, T2, T3
WHERE
( T1.id_t1= T2.id_t1 AND T2.id_t3 = T3.id_t3 )
OR
( T1.id_t3 = T3.id_t3 )
but I was not able to do it.
Does anybody has any solution ?
Thank you in advance
Cristian Zoicas
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
Re: How to create a join ?
Posted by Cristian Zoicas <zo...@medialab.sissa.it>.
> You are right, I figured it out just after I sent the mail, should have
> think twice before sending it :-)
>
n.p.
At the beginning I also thought that I have the solution... :)
> I don't know any way to have such a select with Torque, but you could
> probably do it with Two selects :
>
> one for
>
> T1.id_t1= T2.id_t1 AND T2.id_t3 = T3.id_t3
> and one for
> T1.id_t3 = T3.id_t3
>
Yes. This way it works but the code would become to complicated. We also
have the option to change the databse. It works also with an SQL UNION
( I don't know how to do it with torque :) ) which is in fact what your
solution says.
>And then the collection of objects you wanted is the "sum" of the 2
>collections youn got this way ...
>
> Hope it helps ...
> SaM
Cristi
>
> Cristian Zoicas wrote:
>
> >On Thu, 11 Dec 2003, Samuel Le Berrigaud wrote:
> >
> >
> >
> >>You may want to have a look at this page :
> >>
> >>http://db.apache.org/torque/peers-howto.html (at the bottom of the page)
> >>
> >>the part named "Examples" seems to be what you want ...
> >>
> >>SaM
> >>
> >>
> >
> >Thank you anyway and without being offensive but the example you
> >pointed ( shown below ) is not exactly the same thing in my opinion.
> >
> >
> >
> >>>>BEGIN EXAMPLE <<<<
> >>>>
> >>>>
> >
> > select * from abc where (a < 1 and b > 2) or ( a > 5 and b < 3)
> >
> > Criteria crit = new Criteria();
> > Criteria.Criterion a1 = crit.getNewCriterion(ABC.A, 1, Criteria.LESS_THAN);
> > Criteria.Criterion b2 = crit.getNewCriterion(ABC.B, 2, Criteria.GREATER_THAN);
> > Criteria.Criterion a5 = crit.getNewCriterion(ABC.A, 5, Criteria.GREATER_THAN);
> > Criteria.Criterion b3 = crit.getNewCriterion(ABC.B, 3, Criteria.LESS_THAN);
> >
> > crit.add(a1.and(b2).or(a5.and(b3)));
> >
> >
> >
> >>>>END EXAMPLE <<<
> >>>>
> >>>>
> >
> >Here are the reasons:
> >
> > 1. the FROM caluse contains only one table.
> > 2. The getNewCriterion method allows you to add
> > a) a column name
> > b) a value
> > c) a comparison statement between the column name
> > and the value.
> >
> > and I need a getCriterion which allows me to add :
> > a) a column name;
> > b) a column name;
> > c) a comparison statement between the columns.
> >
> > Does torque lack such a method or is it possible to do it in
> > another way ?
> >
> >Cristian Zoicas
> >
> >
> >
> >
> >
> >
> >
> >>Cristian Zoicas wrote:
> >>
> >>
> >>
> >>>Hello all
> >>>
> >>>I've tried to figure out how to use the Criteria class in
> >>>order to obtain a statement like
> >>>
> >>>SELECT
> >>> *
> >>>FROM
> >>> T1, T2, T3
> >>>WHERE
> >>> ( T1.id_t1= T2.id_t1 AND T2.id_t3 = T3.id_t3 )
> >>> OR
> >>> ( T1.id_t3 = T3.id_t3 )
> >>>
> >>>but I was not able to do it.
> >>>Does anybody has any solution ?
> >>>
> >>>Thank you in advance
> >>>Cristian Zoicas
> >>>
> >>>
> >>>
> >>>---------------------------------------------------------------------
> >>>To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> >>>For additional commands, e-mail: torque-user-help@db.apache.org
> >>>
> >>>
> >>>
> >>>
> >>>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> >>For additional commands, e-mail: torque-user-help@db.apache.org
> >>
> >>
> >>
> >>
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> >For additional commands, e-mail: torque-user-help@db.apache.org
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
Re: How to create a join ?
Posted by Samuel Le Berrigaud <le...@essi.fr>.
You are right, I figured it out just after I sent the mail, should have
think twice before sending it :-)
I don't know any way to have such a select with Torque, but you could
probably do it with Two selects :
one for
T1.id_t1= T2.id_t1 AND T2.id_t3 = T3.id_t3
and one for
T1.id_t3 = T3.id_t3
And then the collection of objects you wanted is the "sum" of the 2 collections youn got this way ...
Hope it helps ...
SaM
Cristian Zoicas wrote:
>On Thu, 11 Dec 2003, Samuel Le Berrigaud wrote:
>
>
>
>>You may want to have a look at this page :
>>
>>http://db.apache.org/torque/peers-howto.html (at the bottom of the page)
>>
>>the part named "Examples" seems to be what you want ...
>>
>>SaM
>>
>>
>
>Thank you anyway and without being offensive but the example you
>pointed ( shown below ) is not exactly the same thing in my opinion.
>
>
>
>>>>BEGIN EXAMPLE <<<<
>>>>
>>>>
>
> select * from abc where (a < 1 and b > 2) or ( a > 5 and b < 3)
>
> Criteria crit = new Criteria();
> Criteria.Criterion a1 = crit.getNewCriterion(ABC.A, 1, Criteria.LESS_THAN);
> Criteria.Criterion b2 = crit.getNewCriterion(ABC.B, 2, Criteria.GREATER_THAN);
> Criteria.Criterion a5 = crit.getNewCriterion(ABC.A, 5, Criteria.GREATER_THAN);
> Criteria.Criterion b3 = crit.getNewCriterion(ABC.B, 3, Criteria.LESS_THAN);
>
> crit.add(a1.and(b2).or(a5.and(b3)));
>
>
>
>>>>END EXAMPLE <<<
>>>>
>>>>
>
>Here are the reasons:
>
> 1. the FROM caluse contains only one table.
> 2. The getNewCriterion method allows you to add
> a) a column name
> b) a value
> c) a comparison statement between the column name
> and the value.
>
> and I need a getCriterion which allows me to add :
> a) a column name;
> b) a column name;
> c) a comparison statement between the columns.
>
> Does torque lack such a method or is it possible to do it in
> another way ?
>
>Cristian Zoicas
>
>
>
>
>
>
>
>>Cristian Zoicas wrote:
>>
>>
>>
>>>Hello all
>>>
>>>I've tried to figure out how to use the Criteria class in
>>>order to obtain a statement like
>>>
>>>SELECT
>>> *
>>>FROM
>>> T1, T2, T3
>>>WHERE
>>> ( T1.id_t1= T2.id_t1 AND T2.id_t3 = T3.id_t3 )
>>> OR
>>> ( T1.id_t3 = T3.id_t3 )
>>>
>>>but I was not able to do it.
>>>Does anybody has any solution ?
>>>
>>>Thank you in advance
>>>Cristian Zoicas
>>>
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
>>>For additional commands, e-mail: torque-user-help@db.apache.org
>>>
>>>
>>>
>>>
>>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
>>For additional commands, e-mail: torque-user-help@db.apache.org
>>
>>
>>
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
>For additional commands, e-mail: torque-user-help@db.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
Re: How to create a join ?
Posted by Cristian Zoicas <zo...@medialab.sissa.it>.
On Thu, 11 Dec 2003, Samuel Le Berrigaud wrote:
> You may want to have a look at this page :
>
> http://db.apache.org/torque/peers-howto.html (at the bottom of the page)
>
> the part named "Examples" seems to be what you want ...
>
> SaM
Thank you anyway and without being offensive but the example you
pointed ( shown below ) is not exactly the same thing in my opinion.
>>> BEGIN EXAMPLE <<<<
select * from abc where (a < 1 and b > 2) or ( a > 5 and b < 3)
Criteria crit = new Criteria();
Criteria.Criterion a1 = crit.getNewCriterion(ABC.A, 1, Criteria.LESS_THAN);
Criteria.Criterion b2 = crit.getNewCriterion(ABC.B, 2, Criteria.GREATER_THAN);
Criteria.Criterion a5 = crit.getNewCriterion(ABC.A, 5, Criteria.GREATER_THAN);
Criteria.Criterion b3 = crit.getNewCriterion(ABC.B, 3, Criteria.LESS_THAN);
crit.add(a1.and(b2).or(a5.and(b3)));
>>> END EXAMPLE <<<
Here are the reasons:
1. the FROM caluse contains only one table.
2. The getNewCriterion method allows you to add
a) a column name
b) a value
c) a comparison statement between the column name
and the value.
and I need a getCriterion which allows me to add :
a) a column name;
b) a column name;
c) a comparison statement between the columns.
Does torque lack such a method or is it possible to do it in
another way ?
Cristian Zoicas
>
> Cristian Zoicas wrote:
>
> >Hello all
> >
> >I've tried to figure out how to use the Criteria class in
> >order to obtain a statement like
> >
> >SELECT
> > *
> >FROM
> > T1, T2, T3
> >WHERE
> > ( T1.id_t1= T2.id_t1 AND T2.id_t3 = T3.id_t3 )
> > OR
> > ( T1.id_t3 = T3.id_t3 )
> >
> >but I was not able to do it.
> >Does anybody has any solution ?
> >
> >Thank you in advance
> >Cristian Zoicas
> >
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> >For additional commands, e-mail: torque-user-help@db.apache.org
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
Re: How to create a join ?
Posted by Samuel Le Berrigaud <le...@essi.fr>.
You may want to have a look at this page :
http://db.apache.org/torque/peers-howto.html (at the bottom of the page)
the part named "Examples" seems to be what you want ...
SaM
Cristian Zoicas wrote:
>Hello all
>
>I've tried to figure out how to use the Criteria class in
>order to obtain a statement like
>
>SELECT
> *
>FROM
> T1, T2, T3
>WHERE
> ( T1.id_t1= T2.id_t1 AND T2.id_t3 = T3.id_t3 )
> OR
> ( T1.id_t3 = T3.id_t3 )
>
>but I was not able to do it.
>Does anybody has any solution ?
>
>Thank you in advance
>Cristian Zoicas
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
>For additional commands, e-mail: torque-user-help@db.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org