user9468951
user9468951

Reputation:

SQLSTATE[42000]: Syntax error or access violation: 1055 for groupby in laravel

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();

Upvotes: 5

Views: 7623

Answers (1)

Shahrukh
Shahrukh

Reputation: 478

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.

Upvotes: 3

Related Questions