2

I don't know if its possible but I'd 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 Answers 2

2

Maybe something like that would 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() . ')')
);
Sign up to request clarification or add additional context in comments.

Comments

0

You may also do it by simply replacing the ($this->select()) subquery variable in the main query (more: https://stackoverflow.com/a/1341463/216084)

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.