Select a,(select x from tab_2 where x=a),(select y from tab_2 where y=a and y='1') from tab_1

解决方案 »

  1.   

    select a,b.x,b.y1 from tab_1,(select x,decode(y,1,y,null) from tab_2) b
    where tab_1.a=b.x(+);
      

  2.   

    请注意,你的 tab_2.y = '1' 这个写法已经把这个条件作为一般的筛选条件了,
    而你实际上是要求把它作为外连接条件,所以改写成 tab_2.y(+) = '1' 就可以了,
    即:Select * from tab_1,tab_2 where tab_1.a = tab_2.x(+) and tab_2.y(+) = '1'
      

  3.   

    呵呵搞错了,没仔细看你要求的结果,你所要求的结果单纯外连接是做不到的,
    需借助其他的办法,把 and tab_2.y = 1 的条件移掉写成:select a,x,decode(y,1,1) y from t,tt where a=x(+);
      

  4.   

    Select * from tab_1,tab_2 where tab_1.a = tab_2.x(+) and tab_2.y(+) = '1'
      

  5.   

    哪位可以说一下Oracle、SQL Server外连接机制的区别
    各自的特点和共通之处...
      

  6.   

    select  t1.*,t2.y
    from   (select t1.a,t2.x
            from   tab_1 t1,tab_2 t2
            where  t1.a=t2.x) t1,tab_2 t2
    where  t1.a=t2.y(+)
    and    t2.y='1';