0
votes

My sql query shows correct in phpmyadmin but when I use it in laravel 5.4 project it shows error

SQLSTATE[42000]: Syntax error or access violation: 1055 'project_management.addprojects.id' isn't in GROUP BY (SQL: SELECT DISTINCT addprojects.id,addprojects.emp_id,sum(tasks.task_weight),tasks.flag from addprojects JOIN tasks ON tasks.proj_id = addprojects.id GROUP BY tasks.proj_id )

DB::select(" SELECT DISTINCT addprojects.proj_name,addprojects.id,
   addprojects.emp_id,sum(tasks.task_weight),tasks.flag from addprojects 
  JOIN tasks ON tasks.proj_id = addprojects.id GROUP BY tasks.proj_id ");
1

1 Answers

0
votes

It is because Laravel uses strict mode. You can disable it from config/database.php you will see in mysql array config

'strict' => true,

turn it to false and your query will work

study more about Strict SQL Mode from here