tags:

views:

49

answers:

1

I want to query as below in cakePHP.so, How can I do query using 'find' function of cakePHP . Help me.

SELECT DISTINCT(Property.City),'city' as Fieldname FROM `properties` as Property WHERE Property.City LIKE 'las%'
+3  A: 

Try:

$this->Property->find( 
  'all', 
  array( 
    'fields'     => array( 'DISTINCT ( Property.city )' ),
    'conditions' => array( 'Property.city LIKE' => 'las%' )
  )

I threw this up from memory, but it should be close. I'm also sure that DISTINCT queries are at least mentioned in the documentation. Probably in the "complex finds" section.

Hope that helps some.

Rob Wilkerson
I also want another field having 'city' as value ..what about that sir?
Jimit
I think this should work, however Cake sometimes chokes on the strangely named fields. If that happens, try `'fields' => array("DISTINCT(Property.city) as 'Property.city'")`
nickf
@jimit, why do you need that in your find query? Just add it afterwards?
nickf
I want 'city' in each and every record so,I can differentiate records..
Jimit