在SQl中获取一次值

问题描述 投票:-2回答:1

这是我的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]);

当我为特定的“company_id”调用branch_id / program_id时,它会多次重复相同的id。但我想只展示一次这些价值观。我能为此做些什么?

mysql sql
1个回答
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的工作方式

© www.soinside.com 2019 - 2024. All rights reserved.