4
$select->joinRight(array('i' => '(SELECT * FROM images ORDER 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 ;)

2 Answers 2

11

Use

$select->joinRight(
    array('i' => new Zend_Db_Expr('(SELECT * FROM images ORDER BY image_id)')),
    'i.ad_id = '. $main .'.id',
    $imarray
);
Sign up to request clarification or add additional context in comments.

2 Comments

I thought that, but I was in good mood. That why it's not RTFM :D
BTW: I think that if you replaced the string with Zend_Db_Select object it would work as well....
5

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.