Take the 2-minute tour ×

I need to find findManyToManyRowset with order by and group by selects for intersection table.

SQL for intersection sub select looks like:

$order = "select *
from intersection
order by someCol desc";

$group = "select order.*
from ($order) as order
group by order.otherCol";

result sub select string is $group.

5th parameter $select of findManyToManyRowset should be Zend_Db_Table_Select, but I'm stuck at this poin, becouse I can't do true sub select with Zend_Db_Table_Select and becouse in findManyToManyRowset(..) there is strings

if ($select === null) {
    $select = $matchTable->select();
} else {

           ->joinInner(array('m' `enter code here`=> $matchName), $joinCond, Zend_Db_Select::SQL_WILDCARD, $matchSchema)

and they are breaking all I do in $select ($group)

share|improve this question

1 Answer 1

problem solved.

I'v change SQL string this way


from someTable st1
where groupCol =
    from someTable st2
        and st1.secondId=st2.secondId
        and etc
--and groupResult=1;

so I have same result without subselect of order by and without join's.

Zend code:

    $matchTable,$intersectionTable - should be instance of Zend_Db_Table_Abstract with correct reference map

        $max = $intersectionTable->select()
                ->from(array('mx' => 'intersectionTableName'), new Zend_Db_Expr("max(mx.groupCol)"))
                ->where('i.firstId = mx.firstId')
                ->where('i.secondId = mx.secondId')
                -> etc ;

        $select = $matchTable->select()
//                  ->where('i.groupResult = ?', true) optional, in case we would like to filter result rowset by grouped value
                    ->where('i.groupCol = ?', $max);

        $result = $row->findManyToManyRowset($matchTable, $intersectionTable, null, null, $select);
share|improve this answer

Your Answer


