How do I create a Zend_Db_Select with nested queries?

I don't know if this is possible, but I would like to make it a Zend_Db_Select object and I don't know how

SELECT *
FROM MyTable MT1
WHERE MT1.date = (
     SELECT MAX(MT2.date)
     FROM MyTable MT2
)

      

+2


a source to share


2 answers


Perhaps something like this will work:



$nestedSelect = $db->select()->from(
    array('MT2' => 'MyTable'),
    new Zend_Db_Expr('MAX(MT2.date)')
);

$select = $db->select()->from(
    array('MT1', 'MyTable')
)->where(
    'MT1.date = ?', new Zend_Db_Expr('(' . $nestedSelect->toString() . ')')
);

      

+2


a source


You can also do this by simply replacing the subquery variable ( $this->select()

) in the main query (more: fooobar.com/questions/190125 / ... )



0


a source







All Articles