Watch::find()->select(['fl_serial.*,COUNT(*) AS total_count']) ->leftJoin(['fl_serial',"fl_serial`.`id`=`fl_watch`.`id_serial`])
->where(['fl_watch.active'=>1])->groupBy('fl_watch.id_serial')->orderBy(['total_count'=>SORT_DESC])->limit(10)->all();
Syntax error or access violation: 1064 You have an error in your SQL syntaxYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `fl_watch`.`active`=1 GROUP BY `fl_watch`.`id_serial` ORDER BY `total_coun' at line 1
The SQL being executed was: SELECT fl_serial.*,COUNT(*) AS total_count FROM `fl_watch` LEFT JOIN `fl_serial` WHERE `fl_watch`.`active`=1 GROUP BY `fl_watch`.`id_serial` ORDER BY `total_count` DESC LIMIT 10
leftJoin('fl_serial',"fl_serial`.`id`=`fl_watch`.`id_serial`)
//select(['fl_serial.*,COUNT(*) AS total_count'])
select('fl_serial.*, COUNT(*) AS total_count')
// or so
select(['fl_serial.*', 'COUNT(*) AS total_count'])
Find more questions by tags Yii