title: CodeIgniter: How To Do a Select (Distinct Fieldname) MySQL Query
body: <p>I'm trying to retrieve a count of all unique values in a field.</p>
  
  <p>Example SQL:</p>
  
  <pre><code>SELECT count(distinct accessid) FROM (`accesslog`) WHERE record = '123'
  </code></pre>
  
  <p>How can I do this kind of query inside of CodeIgniter?</p>
  
  <p>I know I can use <code>$this-&gt;db-&gt;query()</code>, and write my own SQL query, but I have other requirements that I want to use <code>$this-&gt;db-&gt;where()</code> for. If I use <code>-&gt;query()</code> though I have to write the whole query myself.</p>