title: codeigniter active records aggregate not working
body: <p>I'm using Codeigniter, what I want to do is a query that returns joined table (item_gallery) gallery_id is lowest value. while main query ordered by desc of items post_date</p>
  
  <p>the below code group_by select random value of item_gallery gallery_id. but i want the lowest value of item_gallery gallery_id.</p>
  
  <pre><code>  public function shopItems($id) {
  
      $this-&gt;db-&gt;select("*,MIN(item_gallery.gallery_id)");
      $this-&gt;db-&gt;from('items');
      $this-&gt;db-&gt;join('item_gallery', 'items.id = item_gallery.item_id', 'left');
      $this-&gt;db-&gt;where('items.user_id', $id);     
      $this-&gt;db-&gt;order_by('items.post_date', 'Desc');
      $this-&gt;db-&gt;group_by("item_gallery.item_id");
      $query = $this-&gt;db-&gt;get();
      return $query-&gt;result();
  }
  </code></pre>
  
  <p>database Structure</p>
  
  <p>items table</p>
  
  <pre><code>|    id    |  slug  |  user_id  |  post_date |
  
  |    12    |  test  |    111    |  12/5/2017 |
  </code></pre>
  
  <p>items Gallery</p>
  
  <pre><code>| gallery_id |  item_id  |     image     | 
  
  |     121    |    12     |  profile.png  |   -- i want this record selected
  |     122    |    12     |  gallery.png  | 
  </code></pre>