Laravel Sql语法错误

时间:2016-12-01 07:16:12

标签: mysql laravel laravel-5.3

这是我的Laravel查询:

$items =  DashboardItem::distinct()->where('dashboard_id',$dashboard->id)->groupBy('type')->get();

我在此查询中遇到SQLSTATE[42000]: Syntax error or access violation: 1055错误。

错误:

SQLSTATE[42000]: Syntax error or access violation: 1055 'testapp.dashboard_items.id' isn't in GROUP BY (SQL: select distinct * from `dashboard_items` where `dashboard_id` = 3 group by `type`)

Sql Query:

select distinct * from `dashboard_items` where `dashboard_id` = 3 group by `type`

但是当在PHPMyAdmin中运行这个SQL查询时,我得到了结果

1 个答案:

答案 0 :(得分:0)

试试这个

$items =  DB::table('dashboard_items')->where('dashboard_id',$dashboard->id)->groupBy('type')->distinct()->get();