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%'
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%'
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.