I’m trying to use the MAX function of MySQL to retrieve the latest dates from my table.
$_updates = Mage::getModel('ticket/updates')->getCollection();
$_updates->getSelect()->columns('MAX(created) as max_created')->group(array('status_id'));
This is the resulting query:
SELECT `main_table`.*, MAX(created) AS `max_created` FROM `em_ticket_updates` AS `main_table` GROUP BY `status_id`
The problem with this is that if all the fields are included (main_table.*) it does not function correctly.
Is there a way to remove main_table.* from the query and only use specific fields?
Thanks.
A Zend trick can be used here.
NOTE:
For EAV collection you must re-add the
entity_idor you will have an error when the collection is loaded.