开发者

Zend Framework: Zend_Db_Select - how to join custom subquery table?

$select->joinRight(array('i' => '(SELECT * FROM images 开发者_如何学CORDER BY image_id)'),'i.ad_id = '. $main .'.id',$imarray);

Like that doesn't work. Subquery getting inside quotes.

Like that:

RIGHT JOIN `(SELECT * FROM images ORDER BY image_id)` AS `i` ON i.ad_id = a.id

Thanks ;)


Use

$select->joinRight(
    array('i' => new Zend_Db_Expr('(SELECT * FROM images ORDER BY image_id)')),
    'i.ad_id = '. $main .'.id',
    $imarray
);


I feel This is easier to read and navigate...

      $sub = $this->select()
            ->setIntegrityCheck(false)
            ->from(array('i' => 'images'), array('*'))
            ->order('i.image_id');

$select = $this->select()
             ->setIntegrityCheck(false)
             ->from(array('m' => 'MAIN_TABLE'), array('*'))
             ->joinRight(array('i' => $sub), 'i.ad_id = m.id', array('*'));

   return $this->select($select);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜