【发布时间】:2018-05-20 15:16:39
【问题描述】:
你好! ,我在使用查询生成器的 laravel 5.5 上调用 sql 时遇到问题。当我这样做时
$result = DB::table(self::$TABLA_COMPONENTE)
->join(self::$TABLA_ARCHIVOS ,self::$TABLA_COMPONENTE.'.com_id','=',self::$TABLA_ARCHIVOS.'.com_id')
->select(self::$TABLA_COMPONENTE.'.*',DB::raw('group_concat('.self::$TABLA_ARCHIVOS.'.ar_url) as com_archivos'))
->where(self::$TABLA_COMPONENTE.'.com_id',$id)->first();
我收到以下错误
SQLSTATE[42000]:语法错误或访问冲突:1140 如果没有 GROUP BY 子句( SQL: select
componente.*, group_concat(archivos.ar_url) as com_archivos fromcomponenteinner joinarchivosoncomponente.com_id=archivos.com_idwherecomponente.@987 = 2 限制 1)
这是我使用 ->toSql() 得到的原始 sql
This is the sql with ->toSql()
"select `componente`.*, group_concat(archivos.ar_url) as com_archivos from `componente` inner join `archivos` on `componente`.`com_id` = `archivos`.`com_id` where `componente`.`com_id` = ?
它在 Phpmyadmin 上运行良好。
我也尝试过使用 Group by,但没有成功。
如果您能帮助我解决问题,我将不胜感激!
【问题讨论】:
标签: sql laravel mariadb query-builder laravel-5.5