CodeIgniter Forums
Order_by and Group_by Problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Order_by and Group_by Problem (/thread-26786.html)



Order_by and Group_by Problem - El Forum - 01-23-2010

[eluser]Unknown[/eluser]
I have been struggling to select the latest record (message) of each user in my database.

I am joining two tables to generate the data I need to display: r_user and r_logbook


Code:
$this->db->join('r_logbook', 'r_logbook.user_id = r_user.id');
$this->db->group_by('r_user.id');
$this->db->order_by('r_logbook.id');
        
$query = $this->db->get('r_user');
        
return $query->result_array();

This obviously doesn't work, but is the best explanation of what I'd like to do. There must be another direction from which I could approach this, please let me know what you think or if you need any other info.