Query problem


I have 2 tables: content and vote. In vote I have content_id and vote_id(which is AI, PK). I want to make a query and get the content sorted by vote count. How can I achieve that?



in SQL you can do something like that:

select content_id, count('a') from vote

group by content_id

order by count('a')

For the way to use this in a Yii application, you should tell us more about the place to show the result.

I’m trying to use with cactivedataprovder and after that pass the result to a view.

The criteria property can be used to specify various query options.

Yes, I know. I just need to structure my query and for now I have no idea how to sort the info from the content table according to the vote count in the vote table…

You can also find informations in this post:


just get count of vote and order by that fiels,


$criteria->condition = 'ORDER BY count(vote{Relation_Lable}.vote{Field_Name})';