这种情况下,通常是这两张表的关系存在一对多的关系,所以就会出现重复情况,这种情况下,通常需要用子查询,根据规则去重复之后,再次关联,即可出现准确数据。但是子查询去重复的逻辑需要您根据自己业务中来。我随便举个例子:
假设A表和B表关联(关联列为A),但B表中存在一些粒度重复(A、B、C列),而我要去重复
select * from tableA a
join (select distinct A,B,C tableB) b on a.A=b.A
SELECT
a1.name,
a1.type1,
a1.type2,
b1.name,
b1.name,
b1.type3,
b1.type4
FROM
( SELECT row_number () over ( partition BY name ORDER BY type1, type2 ) AS id, name, type1, type2 FROM a ) a1
full outer join
( SELECT row_number () over ( partition BY name ORDER BY type3, type4 ) AS id, name, type3, type4 FROM b ) b1
ON a1.name = b1.name AND a1.id = b1.id
--补充一点:mysql不支持full outer join,所以该语句在mysql下不能执行