ZKX's LAB

left join重复数据 mysql left join 右表存在重复数据,怎么处理

2021-04-08知识3

mysql left join 右表存在重复数据,怎么处理 使用 left join 是在 两个表连接之后 保留左表有数据但是右边为空的数据也就是说右边有重复数据(多条数据对应左边表一条数据。

SQL left join 数据重复 1、Select 语句 加 Distinct2、考虑部分记录可能已经存在于 Test 表,所以 Insert into Test 的时候 加个 Where 语句例如Insert Into Test(itemno,f_itemno)select distinct bg.goodsCode as itemno,isnull(bg2.goodsCode,'0000')as f_itemnofrom[MESBT].[dbo].[SJ_nParts]sn查询本级物料及数量left join[MESBT].[dbo].[BK_goods]bg on sn.goodsId=bg.goodsId查询上级物料left join[MESBT].[dbo].[SJ_nParts]sn2 on sn2.parentId=sn.partIdleft join[MESBT].[dbo].[BK_goods]bg2 on sn2.goodsId=bg2.goodsIdLeft Join Test t On bg.goodsCode=t.itemno And isnull(bg2.goodsCode,'0000')=t.f_itemnoWhere t.itemno is null And t.f_itemno is null

Sql用left join查询结果的重复行数据怎么去掉?如图 select Sno,Sname,concat(Cname)as Cname fromselect sc.Id,s.Sname,c.Cname from SelectCourse scleft join Student s on s.Sno=sc.Snoleft join Course c on c.Cid=sc.Cidt group by Sno;

随机阅读

qrcode
访问手机版