查找两个表之间的重复项

find duplicate between two tables

我有 2 tables 说 A 和 B,在 table A 中有一个额外的列。 我想找到 table B 中存在的 table A 的重复记录。如果找到,我想用它在 table B 中也包含记录的标志更新 table A 的列。我在 table 中都没有主键。 到目前为止,我已经尝试使用 union all 进行查询。

Select * from (
Select rownum over (partition by  ename,enum order by enum) r ,* from
(Select *from a
Union all
Select * from B) data
)d where r>1

它不起作用,我被卡住了。它是一个 oracle 查询。在同一个查询中,如果所有列都匹配到 table B,我想将 table A 列更新为 1,否则为 0

你的问题缺少很多信息,但如果我理解正确,你可以使用EXISTS():

UPDATE a
SET a.YourFlag = 1
WHERE EXISTS(SELECT 1 FROM b
             WHERE a.ename = b.ename and a.enum = b.enum)

根据您的查询,我假设表之间的关系是 ename,enum?如果不是这种情况,请将子查询中的 where 子句更改为您的关系。