Java 我们可以使用anyjoin删除表中的重复行吗?

Java 我们可以使用anyjoin删除表中的重复行吗?,java,sql,oracle11g,Java,Sql,Oracle11g,假设 T1: T2: 对此的确切查询是什么,使用Join删除重复的行 select * from T1 MINUS select * from T2 这将只获取不在T2中的T1行。尝试以下操作: delete from t1 a where not exists(select * from t2 b where a.col1=b.col1 and a.col2=b.col2); 如果希望T1中不存在的T2行具有联接,则使用左联接: select T1.* from T1 left join

假设

T1:

T2:

对此的确切查询是什么,使用Join删除重复的行

select * from T1
MINUS
select * from T2
这将只获取不在T2中的T1行。

尝试以下操作:

delete from t1 a where not exists(select * from t2 b where a.col1=b.col1 and a.col2=b.col2);

如果希望
T1
中不存在的
T2
行具有联接,则使用
左联接

select T1.*
from T1 left join T2
on T2.col1 = T1.col1 and T2.col2 = T1.col2
where T2.col1 is null
select
  coalesce(T1.col1, T2.col1) col1,
  coalesce(T1.col2, T2.col2) col2
from T1 full outer join T2
on T2.col1 = T1.col1 and T2.col2 = T1.col2
where T1.col1 is null or T2.col1 is null
如果需要在这两个表中不常见的行,可以使用
完全外部联接来实现:

select T1.*
from T1 left join T2
on T2.col1 = T1.col1 and T2.col2 = T1.col2
where T2.col1 is null
select
  coalesce(T1.col1, T2.col1) col1,
  coalesce(T1.col2, T2.col2) col2
from T1 full outer join T2
on T2.col1 = T1.col1 and T2.col2 = T1.col2
where T1.col1 is null or T2.col1 is null
WHERE
子句中的条件确保只返回属于一个表而不属于另一个表的行。
请参阅。
结果:


在您的示例中,您认为哪一行是重复的?这里没有足够的信息-您是否试图从T1中删除T2中存在的行?请向我们显示您期望的结果。谢谢,但是我们可以使用联接来执行相同的操作吗oracle@NaveenArora
T1.col1不为空
也将返回重复项。检查我答案中的演示。
> COL1 | COL2
> ---: | :---
>    1 | a