0

When execute my query , I get error message like below.

$ads = DB::table('ads')
        ->join('adimages','adimages.ad_id','=','ads.id')
        ->select(
            'adimages.ad_id',
            'ads.ad_title',
            'ads.created_at',
            'ads.beds',
            'ads.baths',
            'ads.landmark',
            'ads.city',
            'ads.price',
            'adimages.photo'
        )
        ->groupBy('adimages.ad_id')
        ->get();

Here is the error I'm getting.

SQLSTATE[42000]: Syntax error or access violation: 1055 'nekton.ads.ad_title' isn't in GROUP BY (SQL: select adimages.ad_id, ads.ad_title, ads.created_at, ads.beds, ads.baths, ads.landmark, ads.city, ads.price, adimages.photo from ads inner join adimages on adimages.ad_id = ads.id group by adimages.ad_id)

Lakhwinder Singh
  • 5,536
  • 5
  • 27
  • 52

1 Answers1

0

In Laravel, you need to disable strict key in database.php file. Please follow below steps

1. Open config/database.php
2. Find strict key inside mysql connection settings
3. Set the value to false

I think this will help you.

Lakhwinder Singh
  • 5,536
  • 5
  • 27
  • 52
  • While setting `"strict" => false` in the Laravel config will disable `ONLY_FULL_GROUP_BY` which appears to be the cause of the issue. Doing so will result in unexpected results by the improper use of `GROUP BY` statements, as [MySQL is free to choose any value](https://dev.mysql.com/doc/refman/5.7/en/group-by-handling.html) from the columns that are not in the grouped data set. Another alternative is to use `SELECT ANY_VALUE(ads.ad_title) AS ad_title`. – Will B. May 20 '19 at 13:26