Monday, October 5, 2009

Re: sorting records with order by and group by

Do you mean that you executed the query from the Cake debug information directly on your mysql-server ?

If that is the case I have no idea where the difference in results is coming from ...

On Mon, Oct 5, 2009 at 8:32 AM, vekija <vedran.kontosic@gmail.com> wrote:

Hi,

I'm having a problem with sorting the recordset with order by and
group by statements. Would appreciate any help.

There are 2 models, Team and Vote (Team has many Votes) and I want to
order teams based on the number of votes they got.

Here's the find call:
$teams = $this->find('all', array('fields' => 'Vote.team_id', 'order'
=> 'COUNT('Vote.team_id'), 'group' => 'Vote.team_id'));

At the moment there' s only one team in the database with 3 votes.
However, the above query returns 2 (duplicate) records but when I
place the same query directly in the mysql it works as expected and I
get only one.

Any ideas?

thank you




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: