为了账号安全,请及时绑定邮箱和手机立即绑定

Laravel Distinct 查询在我的项目中不起作用

Laravel Distinct 查询在我的项目中不起作用

PHP
HUWWW 2023-04-28 14:14:23
在我的 laravel 项目中,我加入了 2 个以上的表,但问题是在表中location_services,有多个具有相同 location_id 和 services_id 的条目。在这种情况下,我只想取一行。以下是我的查询。这里有什么问题。请帮助我解决它   $loc_services = Clinic::select('*')                         ->join('locations', 'locations.clinicID', '=', 'clinics.clinicID')                         ->join('location_services', 'location_services.locationID', '=', 'locations.locationID')                         ->join('services', 'services.serviceID', '=', 'location_services.serviceID')                         ->whereIn('services.serviceID',$services_id)                         ->where('clinics.api_key','=',$apiKey)                          ->get();请帮忙。我想从在不同位置提供各种服务的诊所表中检索所有数据。每个位置可能有也可能没有超过一项服务
查看完整描述

1 回答

?
隔江千里

TA贡献1906条经验 获得超10个赞

您可以使用groupBy()方法来实现目标。get()只需在方法调用之前添加此方法。

groupBy('location_services.locationID', 'location_services.serviceID')


查看完整回答
反对 回复 2023-04-28
  • 1 回答
  • 0 关注
  • 82 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信