如何在不丢失Oracle中的重复值的情况下交叉两个表?
TAB1:
A A B C
TAB2:
A A B D
输出:
A A B
答案 0 :(得分:2)
子查询将过滤行:
select *
from tab1
where col in (select col from tab2)
答案 1 :(得分:2)
如果我理解正确:
select a.*, row_number() over (partition by col1 order by col1)
from a
intersect
select b.*, row_number() over (partition by col1 order by col1)
from b;
这会为每一行添加一个新的序列号。相交将达到匹配的数字。
这使用partition by col1
- col1
是任意的。您可能需要在partition by
中包含所有列。