5

I want to group all duplicate rows but I got error

Here is below error

Illuminate\Database\QueryException: SQLSTATE[42000]: Syntax error or access violation: 1055 'car_web.dependencies.id' isn't in GROUP BY (SQL: select * from dependencies where make_dep = 3 group by model_dep) in file C:\xampp\htdocs\car-parts-web\vendor\laravel\framework\src\Illuminate\Database\Connection.php on line 671

I also change in database.php file

'strict' => true,
'modes' => [
    //'ONLY_FULL_GROUP_BY', // Disable this to allow grouping by one column
    'STRICT_TRANS_TABLES',
    'NO_ZERO_IN_DATE',
    'NO_ZERO_DATE',
    'ERROR_FOR_DIVISION_BY_ZERO',
    'NO_AUTO_CREATE_USER',
    'NO_ENGINE_SUBSTITUTION'
],

but give same error

here is below my query

$data = DB::table('dependencies')
        ->where('make_dep', '=', $make)
        ->groupBy('model_dep')
        ->get();
4
  • You typically GROUP BY the same columns as you SELECT, except those who are arguments tp set functions. Commented Sep 21, 2020 at 11:47
  • After changed, have you clear the caches? php artisan config:cache Commented Sep 21, 2020 at 11:48
  • no cache not cleared let me cleared Commented Sep 21, 2020 at 11:49
  • try in database.php inside mysql array 'strict' => false, make it false and try Commented Sep 21, 2020 at 11:59

1 Answer 1

3

You are confused in GROUP BY statement because in GROUP BY we need to use any aggregate function like SUM, COUNT, ... .

If you want to remove duplicate rows you can simply use DISTINCT method, if you want to group data you need any aggregate function.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.