Answer the question
In order to leave comments, you need to log in
Why doesn't leftJoin work?
This is how I write
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
Answer the question
In order to leave comments, you need to log in
If you use a framework - use its methods and principles. Create a connection in the model and do a join through it.
www.yiiframework.com/doc-2.0/guide-db-active-recor... namely the "Joining with Relations" section
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question