phpmysqlzend-frameworkzend-db-table

How can I Select the MAX of a Column using Zend_Db_Table?


What is the easiest, simplest way to select the max of a column from a table using Zend_Db_Table? Basically, I just want to run this query in Zend:

SELECT MAX(id) AS maxID FROM myTable;

Solution

  • You need to use Zend_Db_Expr to use mysql functions:

    return $this->fetchAll(
                $this->select()
                    ->from($this, array(new Zend_Db_Expr('max(id) as maxId')))
                )
        );