我一直在构建一个查询,如果表 2 和表 3 满足条件,我需要从表 1 中选择项目。
我有这三个表:
company -> company_id, name, location
services -> company_id, service_id, service_name
date -> service_id, service_date //should i include company_id here?
如果搜索匹配services->service_name and date->service_date,我想选择company -> name and location。
如何 JOIN 表以获得所需的结果?
最佳答案
这没有经过测试,但它会像下面这样:
$query = Company::query()
->select(['company.name','company.location'])
->leftJoin('services', 'services.company_id', '=', 'company.company_id')
->leftJoin('date', 'date.service_id', '=', 'services.service_id')
->where('services.service_name', $servicename)
->where('date.service_date', $servicedate);
关于php - Laravel [QUERY] 如何从表 1 中选择条件必须满足表 2 和表 3 的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46307674/