我正在加入两个表 A 和 B。我的查询看起来像这样。
select id, name, sum(qty)
from table 1
left join table 2 on table1.id = table2.id and table2.column = XXXX
group by 1,2
我想知道这个连接是否在表 1 中创建了任何重复的行。
我正在使用 teradata SQL
我正在加入两个表 A 和 B。我的查询看起来像这样。
select id, name, sum(qty)
from table 1
left join table 2 on table1.id = table2.id and table2.column = XXXX
group by 1,2
我想知道这个连接是否在表 1 中创建了任何重复的行。
我正在使用 teradata SQL
我了解您想知道是否存在table2与您的连接条件匹配的多行。这是一个用于此目的的查询:
select t2.id
from table2 t2
where
t2.colum = 'XXXX'
and exists (select 1 from table1 t1 where t1.id = t2.id)
group by t2.id
having count(*) > 1
该查询返回的任何行都会复制现有联接中的行。
一种方法可能是类似于
select id, name, sum(qty)
from table 1 as t1
left join table 2 as t2 on table1.id = table2.id and table2.column = XXXX
where t1.id in (select distinct id from table 1 )
Distinct 检查行区别,您提到需要检查重复项的唯一列是 ID。