Zend_Db_Select the last row from each group

Posted . Visible to the public.

Get the last entry of each applicant in history table:

$installer = $this;
$db = $installer->getConnection();

$table  = $installer->getTable('table/name');
$select = $db->select()
    ->from(['t1'=>$table], ['log_id', 'applicant_id', 'grade', 'attendance'])
    ->joinLeft(['t2'=>$table], 't1.applicant_id = t2.applicant_id AND t1.created_at < t2.created_at', [])
    ->where('t2.created_at IS NULL');
$items = $db->fetchAll($select);
kiatng
Last edit
kiatng
Posted by kiatng to OpenMage (2018-08-03 06:58)