我只想跳过数据库中的重复数据,我的外键正在重复,所以我只想跳过重复的条目并获取最新信息,只有我的控制器是这样的
$old=DB::table('tabl-1')
->leftJoin('tbl-2','tabl1.id','=','tabl2.tabl1_id')
->whereDate('created_at','<' ,Carbon::today())
->select('tbl1.name as name','tbl1.class as class','tabl2.table1_id')
->distinct('tabl2.table1_id')
->get()
->toArray();发布于 2021-04-16 02:07:34
DB::table('first')->leftJoin('second', 'first.id', '=', 'second.first_id')
->whereDate('first.created_at', '<', Carbon::today())
->select('first.name as name', 'first.class as class', 'second.first_id')
->groupBy('second.first_id')->get()->toArray();尝试groupBy,因为distinct()在其中没有参数
https://stackoverflow.com/questions/67113547
复制相似问题