title: Converting Sql query to CodeIgniter Active Records
body: <p>I wanted to query only those items that have a highest likes.</p>
  
  <p>This is the sql query I want to convert into CodeIgnitor's Active Records:</p>
  
  <pre><code>SELECT *, SUM(like) as totalLikes
  FROM tbl_like
  GROUP BY uploadID
  ORDER BY totalLikes DESC
  LIMIT 2
  </code></pre>
  
  <p><strong>CodeIgniter:</strong></p>
  
  <pre><code>public function get_cheezyPic(){
        $this-&gt;db-&gt;select('uploadID, SUM(like) as totalLikes');
        $this-&gt;db-&gt;from('tbl_like');
        $this-&gt;db-&gt;group_by('uploadID');
        $this-&gt;db-&gt;order_by('totalLikes DESC');
        $this-&gt;db-&gt;limit(2);
  
        $query= $this-&gt;db-&gt;get();
  
        return $query-&gt;result_array();}
  </code></pre>
  
  <p>But when I try to run this code, I've got this error </p>
  
  <blockquote>
    <p>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'like) as totalLikes FROM (<code>tbl_like</code>) GROUP BY <code>uploadID</code> ORDER BY <code>totalLikes</code> ' at line 1</p>
  </blockquote>
  
  <pre><code>SELECT `uploadID`, SUM(like) as totalLikes FROM (`tbl_like`) GROUP BY `uploadID` ORDER BY `totalLikes` desc LIMIT 2
  </code></pre>
  
  <p>What's wrong with this code?</p>
  
  <p>Thanks for the help.</p>