日期:2014-05-16  浏览次数:20637 次

oracle表间多字段连接

问题如下:

SELECT *
? FROM table1 a, table2 b,
?WHERE a.1 = b.1
?? AND a.2 = b.2
?? AND a.3 = b.3
?? ----------
?? 初始 a表里有数据? b表里是空的 想用a的那三个字段联合起来 join b 的那三个字段

方法1:

select * from
table1 left outer join table2
on a.1=b.1 and a.2=b.2 and? a.3=b.3

方法2:

<!--StartFragment -->
SELECT?a.*
??FROM?table1?a,?table2?b,
?WHERE?a.1?=?b.1(+)
???AND?a.2?=?b.2(+)
???AND?a.3?=?b.3(+)
方法3:
<!--StartFragment -->
a.1||a.2||a.3做主键
b也同样处理,然后再外连接
SELECT a.*
? FROM (select a.1||a.2||a.3 al from table1) a, (select b.1||b.2||b.3 bl from table2) b,
?WHERE a.al = b.bl(+)
?