CakePHP and SQL Server 2008, Group By not working -


whenever a:

$this->job->find('all', array(         'group' => array('job.some_field'),         'recursive' => -1     )); 

i :

sql error: column 'jobs.id' invalid in select list because not contained in either aggregate function or group clause. 

with mysql works fine sql server 2008 seems group doesn't work anymore. how fix this? in advance sql gurus

the query translated this:

select  *    job group         some_field 

this not valid query according sql standards, however, works in mysql because of mysql's group by extensions.

you need leave grouped columns or aggregates in select clause:

select  some_field, count(*)    job group         some_field 

with this:

$this->job->find('all', array(         'fields' => array('job.some_field', 'count(*)'),         'group' => array('job.some_field'),         'recursive' => -1     )); 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -