这是我的SQl:
$branches = DB::select('select distinct programs.id as program_id,programs.program_name as program_name,branches.id as branch_id,branches.branch_name as branch_name from programs,branches where programs.company_id=? and branches.company_id=?' ,[$company_id,$company_id]);
bu当我为特定的“ company_id”调用branch_id / program_id时,它会重复多次相同的ID。但我只想显示一次值。我该怎么办?
答案 0 :(得分:0)
将查询更改为
select distinct programs.id as program_id,programs.program_name as program_name,branches.id as branch_id,branches.branch_name as branch_name from programs,branches where programs.company_id=? and branches.company_id=programs.company_id
在Internet上查找SQL连接的工作方式