Thursday, March 16, 2017

How i can re-write this in a manner it does provide the same output

i have mysql query like this:

select bp.id, count(*) as total from blog_posts bp join tagged tg on tg.taggable_id=bp.id and tg.taggable_type='App\\Storage\\BlogPost' join tags t on t.id=tg.tag_id where bp.user_id=1 group by t.id order by total desc, t.count desc limit 3

and i got an error:

Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'example.bp.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

How i can re-write this in a manner it does provide the same output?

I work in MySQL 5.7.17 with Homestead Laravel



via Muh Ghazali Akbar

Advertisement