我要进行三个表的连接,想要其中两个表的记录全部保留,请问如何连接?

解决方案 »

  1.   

    例如表A有字段aa,表B有字段bb,表C有字段cc,它们可作等值连接,现在的问题是现保留表A和表B中的所有记录,肯定要用到外连接,但是如何用呢?
      

  2.   

    select .. from a,c where a.aa(+)=c.cc
    union 
    select .. from a,b where a.aa(+)=b.bb
      

  3.   

    依你的意思还与c连接干啥,直接
    select aa from a
    union all
    select bb from b
    不就可以了吗!
      

  4.   

    select a.a1,a.a2,a.a3,b.b1,b.b2,b.b3,c.c1 from a,b,c where a.id=c.id
      

  5.   

    select tab1.*,tab2.*,tab3.* from tab1,tab2,tab3 where tab1.id=tab3.id(+) and tab2.id=tab3.id(+)
     可保证表1和表2的所有记录被显示,表3仅为满足条件的记录被显示。
      

  6.   

    问题已经解决了,用了union,速度比较慢,还有谁能够提供更好的方案?
    在此感谢Fred_Mark(我心飞扬) 给我的灵感.
    to BlueskyWide(谈趣者):你的根本不行,首先没有三个表连接,其次不能查出A,B表中所包含的所有记录.
      

  7.   

    to BlueskyWide(谈趣者):你的第二个回答出现如下错误:
    ORA-01417: 表可以外部连接到至多一个其它表.
      

  8.   

    select tab1.*,tab2.*,tab3.* from tab1,tab2,tab3 where tab1.id=tab3.id(+) or tab2.id=tab3.id(+)
      

  9.   

    to BlueskyWide(谈趣者) :如下也不行
    select tab1.*,tab2.*,tab3.* from tab1,tab2,tab3 where tab1.id=tab3.id(+) or tab2.id=tab3.id(+)
    出现错误
    ORA-01719: OR 或 in操作数中不允许外部连接运算符(+)
      

  10.   

    try again:select tab1.*,tab3.* from tab1,tab3 where tab1.id=tab3.id(+)
    union
    select tab2.*,tab3.* from tab2,tab3 where tab2.id=tab3.id(+)
      

  11.   

    我已经说了这个可以
    select tab1.*,tab3.* from tab1,tab3 where tab1.id=tab3.id(+) and tab1.id=tab2.id
    union
    select tab2.*,tab3.* from tab2,tab3 where tab2.id=tab3.id(+) and tab1.id=tab2.id
    只是想要一种更快的方案