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;
You can run direct sql, using $db->query();
yours would simply be:
$db->query("SELECT MAX(id) AS maxID FROM myTable");
but if you want the object notation, then you'd do something like this:
$db->select()->from("myTable", array(new Zend_Db_Expr("MAX(id) AS maxID")));
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')))
)
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With