title: select the row with most recent date in table formed by using join and group by
body: <p>i am joining three tables and applying group by to pick a single distinct row of each type. when i join with table marketing_follow i have multiple entries and to pick one i am using group by . now i want to pick the entry with most recent date in follow up table . i've been tryn to get this done for quite some time now and really need some help</p>
  
  <pre><code>public function getRegionWiseUserDetails($array){
  
      $this-&gt;db-&gt;select('mg.region_name, mu.contact_person, mu.contact_number, mu.status, mu.company_name, mu.user_type, mf.follow_up_date, mf.date, mu.user_id');
  
  
     $this-&gt;db-&gt;from('marketing_users as mu');
      $this-&gt;db-&gt;join('marketing_group as mg','mg.id = mu.region_id','left');
      $this-&gt;db-&gt;join('marketing_follow_up as mf','mf.user_id_fk = 
      mu.user_id','left');
     foreach($array as $condition){
         $this-&gt;db-&gt;or_where('mg.id',$condition);
     }
     $this-&gt;db-&gt;order_by('mf.follow_up_date','asc');
     $this-&gt;db-&gt;group_by('mf.user_id_fk');
  
  
     $query = $this-&gt;db-&gt;get();
     return $query-&gt;result_array();
    }
  </code></pre>