title: Using DISTINCT in a CakePHP find function
body: <p>I am writing a CakePHP 1.2 app.  I have a list of people that I want the user to be able to filter on different fields.  For each filterable field, I have a drop down list.  Choose the filter combination, click filter, and the page shows only the records that match.</p>
  
  <p>In people_controller, I have this bit of code:</p>
  
  <pre><code>$first_names = $this-&gt;Person-&gt;find('list', array(
      'fields'=&gt;'first_name',
      'order'=&gt;'Person.first_name ASC',
      'conditions'=&gt; array('Person.status'=&gt;'1')
  ));
  $this-&gt;set('first_names', $first_names);
  </code></pre>
  
  <p>(Status = 1 because I am using a soft delete.)</p>
  
  <p>That creates an ordered list of all first_names.  But duplicates are in there.</p>
  
  <p>Digging around in the Cookbook, I found an example using the DISTINCT keyword and modified my code to use it.</p>
  
  <pre><code>$first_names = $this-&gt;Person-&gt;find('list', array(
      'fields'=&gt;'DISTINCT first_name',
      'order'=&gt;'Person.first_name ASC',
      'conditions'=&gt; array('Person.status'=&gt;'1')
  ));
  </code></pre>
  
  <p>This gives me an SQL error like this:</p>
  
  <pre><code>Query: SELECT `Person`.`id`, DISTINCT `Person`.` first_name` FROM `people` AS `Person`   WHERE `Person`.`status` = 1   ORDER BY `Person`.`first_name` ASC
  </code></pre>
  
  <p>The problem is obvious.  The framework is adding Person.id to the query.  I suspect this comes from using 'list'.</p>
  
  <p>I will use the selected filter to create an SQL statement when the filter button is clicked.  I don't need the is field, but can't get rid of it.</p>
  
  <p>Thank you,
  Frank Luke</p>