目前我有三张表,我要关联前面两张表tab1 left join tab2 然后根据tab1和tab3中一个字段关联三张表tab3
请求达人,帮忙写个例子
在线等!

解决方案 »

  1.   

    假设table1与table2 table3关联的字段为id 
    select * from table3 t where t.id in(
       select table1.id,table2.id
            from  table1 left join table2
             on table1.id= table2.id
    );
      

  2.   

    select * 
    from t1,
         t2,
         t3
    where t1.id = t3.id
    and   t1.id = t2.id(+);
      

  3.   

    select a.*,b.*,c.*
      from a left join b on a.col = b.col 
             left join c on a.col = c.col
      

  4.   

    select * 
    from t1, 
         t2, 
         t3 
    where t1.id = t3.id(+)
    and   t1.name = t2.name(+);
    -------------
    oracle用(+)是很简单明了,db2要用outer join in。工作中要长期使用oracle和db2数据库,总体感觉oracle的建表,查询等的sql语句要比db2的简单易懂