Question: I want to use WhereIn and Groupby in the same query to fetch Result.

I've tried this:

```
$loadids=explode("#@*",$reciptdet->loading_id);
$loadingdatas=DB::table('loading')->groupBy('vehicle_no')->whereIn('id',$loadids)->get();

```

But I got this error message:

> 
> SQLSTATE[42000]: Syntax error or access violation: 1055 'sbrtpt.loading.id' isn't in GROUP BY (SQL: select \* from loading where id in (14, 15, 16) group by vehicle\_no)
> 
> 
>

Answer: 
Without modifiying `config\database.php` file
=============================================

**Set `'strict' => false`** in the `config\database.php` could be a **security issue**. So, a simple Laravel solution could be **first call `get()` and then `groupBy('vehicle_no)`**:

```
$loadids = explode("#@*", $reciptdet->loading_id);
$loadingdatas = DB::table('loading')->whereIn('id', $loadids)->get();
$grouped = $loadingdatas->groupBy('vehicle_no');

```
This restriction makes sense as when you use `GROUP BY` in MySQL, it returns one row for each value in the columns used in `GROUP BY`. So, the values of other columns in the selected rows do not make sense to use anywhere. So, it's always recommended to use the best practice and I would recommend not to disable MySQL Strict Mode. 

Often developers may need rows of a query grouped by the value of a column. Here they don't need only one row per the unique values of the columns. But they need multiple rows grouped by the unique values of a particular column. For some reason, they use `groupBy` Query Builder method of Laravel which generates a MySQL `GROUP BY` query and the developers encounter the above error. 

The solution to their problem is to use `groupBy` Collection method instead. For example,

```
$loadingData = DB::table('loading')
    ->whereIn('id', $loadIds)
    ->get()
    ->groupBy('vehicle_no');

```

This will give them the desired result.