views:

11

answers:

0

Hey, I'm trying to create a query where I reference a table twice. I know how to do this in sql. It looks like this:

   SELECT t1.* 
     FROM Table1 t1 
LEFT JOIN Table1 t2 ON t1.ID = t2.OwnerID 
    WHERE t1.Column1='ok' 
      AND (t1.OwnerID = 0 OR t2.Column1='ok');

This will return all the elements of the table that are "ok" and either don't have an owner or have an owner who is also "ok".

I've tried to use the criteria.addAlias() method, but what it does is this:

   SELECT Table.* 
     FROM Table 
LEFT JOIN Table ON Table.ID = Table.OwnerID , t1 
    WHERE Table.Column1='ok' 
      AND (Table.OwnerID= 0 OR Table.Column1='ok');

The "how to" document on apache's website wasn't of much use. Please let me know if there is a way to get this to work.