$select->joinRight(array('i' => '(SELECT * FROM images ORDER BY image_id)'),'i.ad_id = '. $main .'.id',$imarray);
就像那样不起作用。子查询获取引号。
就像那样:
RIGHT JOIN `(SELECT * FROM images ORDER BY image_id)` AS `i` ON i.ad_id = a.id
谢谢;)
答案 0 :(得分:11)
使用
$select->joinRight(
array('i' => new Zend_Db_Expr('(SELECT * FROM images ORDER BY image_id)')),
'i.ad_id = '. $main .'.id',
$imarray
);
答案 1 :(得分:5)
我觉得这更容易阅读和导航......
$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);