If I write the following query in phpmyadmin, it runs and returns the correct result
select `u`.*, count(t.empid) as totalassignedtask from `users` as `u` left join `tasks` as `t` on `t`.`empid` = `u`.`id` where `u`.`role` = 'user' group by `t`.`empid`
However, if I wrote this query in laravel like this
$allemp = DB::table('users as u')
->leftJoin('tasks as t','t.empid','=','u.id')
->where('u.role','=','user')
->select('u.*',DB::raw('count(t.empid) as totalassignedtask'))
->groupBy('t.empid')
->get();
I get an error:
Illuminate \ Database \ QueryException (42000)
SQLSTATE[42000]: Syntax error or access violation: 1055 'employee.u.id' isn't in GROUP BY (SQL: selectu
.*, count(t.empid) as totalassignedtask fromtasks
ast
left joinusers
asu
ont
.empid
=u
.id
whereu
.role
= user group byt
.empid
)