Please help me convert this SQL to CodeIgniter ActiveRecord without using the following:
$this->db->query('SELECT * FROM (SELECT * FROM inbox ORDER BY created_at DESC) AS query GROUP BY id');
Please help me convert this SQL to CodeIgniter ActiveRecord without using the following:
$this->db->query('SELECT * FROM (SELECT * FROM inbox ORDER BY created_at DESC) AS query GROUP BY id');
CI Active Record does not support subqueries natively. But you can include a subquery library like this one and use it. I've not used this library before, so this is not tested. But should be enough to get you started.
$this->db->select()->from('query')->group_by('id');
$sub = $this->subquery->start_subquery('select');
$sub->select()->from('index')->order_by('created_at', 'DESC');
$this->subquery->end_subquery('query');