You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Frederick Tsang <fr...@kaizensoft.com> on 2004/01/07 09:56:22 UTC

Complex Query with Exists

Hi All,

I have been looking into the mailing list and docs but I am a bit
confused about what I am supposed to use.

This is my problem.

I have a 1:m relationship between a property and propertyDates.
The property Dates contain a startDate and a endDate and describes a
period that is busy.

I need to make a search and find out ALL the properties that do not have
a busy period.

IN SQL it would look something like this.

SELECT * FROM PROPERTY WHERE NOT EXISTS
	(SELECT * FROM PROPERTY_DATES WHERE
			PROPERTY_DATES.PROPERTY_ID=PROPERTY.ID
		        START_DATE < 01/01/04 and
                 	END_DATE < 01/01/04).

However I really don't want to use SQL to do this, I really want to use
OJB. I have seen some things in a thread 'NOT EXISTS CRITERIA' and
explaining the use of a reportQuery but I could not see how to adapt it
to my problem.

Thank you for taking the time to read this.

Frederick Tsang

	


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Complex Query with Exists

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi frederick,

class QueryTest provides a testCase testSubQuery4() that shows how to 
use a subquery referencing attributes of the enclosing query.

hth
jakob

Frederick Tsang wrote:

> Hi All,
> 
> I have been looking into the mailing list and docs but I am a bit
> confused about what I am supposed to use.
> 
> This is my problem.
> 
> I have a 1:m relationship between a property and propertyDates.
> The property Dates contain a startDate and a endDate and describes a
> period that is busy.
> 
> I need to make a search and find out ALL the properties that do not have
> a busy period.
> 
> IN SQL it would look something like this.
> 
> SELECT * FROM PROPERTY WHERE NOT EXISTS
> 	(SELECT * FROM PROPERTY_DATES WHERE
> 			PROPERTY_DATES.PROPERTY_ID=PROPERTY.ID
> 		        START_DATE < 01/01/04 and
>                  	END_DATE < 01/01/04).
> 
> However I really don't want to use SQL to do this, I really want to use
> OJB. I have seen some things in a thread 'NOT EXISTS CRITERIA' and
> explaining the use of a reportQuery but I could not see how to adapt it
> to my problem.
> 
> Thank you for taking the time to read this.
> 
> Frederick Tsang
> 
> 	
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org