php - Laravel Distinct 查询在我的项目中不起作用
问题描述
在我的 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();
请帮忙。
我想从诊所表中检索在不同位置有各种服务的所有数据。每个位置可能有也可能没有超过一项服务
解决方案
您可以使用groupBy()
方法来实现目标。get()
只需在方法调用之前添加此方法即可。
groupBy('location_services.locationID', 'location_services.serviceID')
推荐阅读
- javascript - 错误:模块“DynamicTestModule”导入了意外的值“DomSanitizer”。请添加@NgModule 注释
- java - 仅当线程池中的线程可用于处理消息时,才从 JMS 队列中将消息出队
- wpf - WPF - 按字体名称访问 Roboto 字体时出现问题
- swift - Swift UI(Xcode 12 Beta):无法构建 ContentView.swift
- c# - 在 C# 中处理视频帧(FFMPEG 慢)
- c# - AdColony 插页式广告不显示(Unity Android)
- ios - 内部 iPad 应用分发 - 离线模式
- javascript - 在 Redux 中使用动作创建器的主要好处是什么?
- c# - Teams 中用于 botframework 身份验证的 AAD 版本
- node.js - 使用 mongoose 查询一组嵌入式文档