Make your self a little subclass of criteria, and then put this method in it :
public SimpleCriteria addIn(String columnname, Criteria criteria ) {
try {
String query = getSubQueryString(criteria);
// you might have to adapt this to your adapter.
add( columnname, (Object)(columnname + " in ( " + query + " )"),
CUSTOM );
}
catch (Exception e) {
Log.error( "Couldn't create sub select.", e);
}
return this;
}
and then put this method in there too:
private String getSubQueryString(Criteria criteria) throws TorqueException {
if ( criteria.getSelectColumns().size() != 1 ) {
Log.error("Only one column allowed in subselect.");
throw new TorqueException("Only one column allowed in subselect.");
}
if ( criteria.getBaseTableName() == null ) {
String fullName = criteria.getSelectColumns().get(0);
}
return BasePeer.createQueryString(criteria);
}
then use it like this:
searchCriteria.addIn( SomePeer.SOME_COLUMN,
new Criteria()
.addSelectColumn(SomeOtherPeer.SOME_OTHER_COLUMN)
.add(SomeOtherPeer.YET_SOME_OTHER_COLUMN,"'SOME KNOWN VALUE")
);
Hope that helps.
On Thursday 24 June 2004 8:23 am, [EMAIL PROTECTED] wrote:
> Basically what I am trying to do is avoiding listing all teh columns in the
> select clause a a result of needing to add a group by clause.
>
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, June 22, 2004 7:33 PM
> To: [EMAIL PROTECTED]
> Subject: Subqueries in Torque
>
>
> Hi-
>
> I have searched the archives and have not been able to find a solution to a
> problem I have.
>
> Is anyone familiar with how to produce a subquery in Torque 3.1?
>
> I am trying to achieve the following:
>
> select *
> from table1 as a
> where a.col1 in
> (
> select *
> from table2 as b
> where b.col1 = 'SOME KNOWN VALUE'
> )
>
> Thanks.
>
> Michael
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]