我是 laravel 新手,我想在 laravel 5.4 中编写 mysql 查询。查询就像:
注意:避免列名..
SELECT *
FROM (SELECT DISTINCT *
FROM messages
WHERE (from_id=1 OR to_id=1)
ORDER BY created DESC) as m
GROUP BY `from_id`
我试过但给出错误。
$messages = DB::table('messagetbl')
->select('*')
->Where(function($query) use ($userid){
$query->distinct()
->where('senderid',$userid)
->orWhere('receiverid',$userid)
->orderBy('datetime','desc');
})
->groupBy('senderid')
->get();
错误:
SQLSTATE [42000]:语法错误或访问冲突:1055 SELECT 列表的表达式 #1 不在 GROUP BY 子句中,并且包含在功能上不依赖于 GROUP BY 子句中的列的非聚合列“db.messagetbl.id”;这与 sql_mode=only_full_group_by 不兼容(SQL:select * from
messagetbl
where (senderid
= 8 orreceiverid
= 8) group bysenderid
)
提前致谢。