title: Codeigniter Active Record HAVING clause with aggregate function MAX
body: <p>I'm trying to use an aggregate function with the HAVING clause in a SQL query, using Codeigniter's Active Record.</p>
  
  <pre><code>function get_last_each()
  {
      $this-&gt;load-&gt;database();
      $q = $this-&gt;db-&gt;from('points')-&gt;group_by('nodeid')-&gt;having('max(timestamp)', NULL)-&gt;get();
  
      return $q-&gt;result_array();
  }
  </code></pre>
  
  <p>It gives me a database error:</p>
  
  <pre><code>You have an error in your SQL syntax ...
  SELECT * FROM (`points`) GROUP BY `nodeid` HAVING max(timestamp) = 
  </code></pre>
  
  <p>If I use <code>max(timestamp)</code> in the second argument, the generated query ends like <code>= max(timestamp)</code>. Also used the third parameter to disallow query escaping, without success.</p>
  
  <p>The query runs fine on mysql client:</p>
  
  <pre><code>mysql&gt; select nodeid, timestamp from points group by nodeid having max(timestamp);
  +-----------+---------------+
  | nodeid    | timestamp     |
  +-----------+---------------+
  | 10EF7F    | 1400497730790 |
  | ADCFB2    | 1400501296786 |
  ...
  </code></pre>
  
  <p>How can I achieve this with Codeigniter using having function?</p>