title: How can get unique values from data table using dql?
body: <p>I am having a table in which there is a column in which various values are stored.i want to retrieve unique values from that table using dql.      </p>
  
  <pre><code>         Doctrine_Query::create()
                      -&gt;select('rec.school')
                      -&gt;from('Records rec')                   
                      -&gt;where("rec.city='$city' ")                                    
                      -&gt;execute();        
  </code></pre>
  
  <p>Now i want only unique values. Can anybody tell me how to do that...</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Table Structure:</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `records` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `state` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
   `city` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
   `school` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
   PRIMARY KEY (`id`)
  ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=16334 ;
  </code></pre>
  
  <p>This is the Query I am using:</p>
  
  <pre><code>   Doctrine_Query::create()
            -&gt;select('DISTINCT rec.city')
            -&gt;from('Records rec')                   
            -&gt;where("rec.state = '$state'")                                    
               // -&gt;getSql();
             -&gt;execute();                 
  </code></pre>
  
  <p>Generting Sql for this gives me:</p>
  
  <pre><code>SELECT DISTINCT r.id AS r__id, r.city AS r__city FROM records r WHERE r.state = 'AR'
  </code></pre>
  
  <p>Now check the sql generated::::
    <strong>DISTINCT</strong> is on 'id' column where as i want Distinct on city column. Anybody know how to fix this.</p>
  
  <p><strong>EDIT2</strong></p>
  
  <p>Id is unique cause its an auto incremental value.Ya i have some real duplicates in city column like: Delhi and Delhi. Right.. Now when i am trying to fetch data from it, I am getting Delhi two times. How can i make query like this:</p>
  
  <pre><code>  select DISTINCT rec.city where state="xyz";
  </code></pre>
  
  <p>Cause this will give me the proper output.</p>
  
  <p><strong>EDIT3:</strong></p>
  
  <p>Anybody who can tell me how to figure out this query..???</p>