I want to take how much amount of data based on the product_id taken from the table vote. on laravel this query does not work well but when i try it in mysql i run it fine is there any other solution?
this is a successfully executed query through mysql :
select count(product_id) as total, `v`.*, `p`.`name` from `votes` as `v` left join `products` as `p` on `p`.`id` = (select p1.id from products as p1 where v.product_id = p1.id ) group by v.product_id
and it's a query on laravel that I use using query builder :
$count = DB::table('votes as v')->leftJoin('products as p',function($join){
$join->on('p.id','=',DB::raw('(select p1.id from products as p1 where v.product_id = p1.id )'));
})->select(DB::raw('count(*) as total'),'v.*','p.name')->groupBy('v.product_id')->get();
dd($count);
and i got this error :
"SQLSTATE[42000]: Syntax error or access violation: 1055 'lookbubbledrink.v.id' isn't in GROUP BY (SQL: select count() as total,
v
.,p
.name
fromvotes
asv
left joinproducts
asp
onp
.id
= (select p1.id from products as p1 where v.product_id = p1.id ) group byv
.product_id
I have to use group by product_id only to calculate how much amount of data based on the number of product_id in the vote.