select a.id,b.id
  from (select t1.id from test1 t1 where t1.xh = '123') a,
       (select t2.id from test2 t2 where t2.xh = '456') b
 where a.id = b.id(+)
 
select a.id,b.id
  from test1 a,test2 b
 where a.xh = '123'
   and b.xh = '456'
   and a.id = b.id(+)上面两条sql第一条可以得出b表(+)a表的数据,但是第二条得出的是两个表id相同的数据。
不明白原理,请各位给上一课。

解决方案 »

  1.   

    是加了and b.xh = '456'这个的原因。在执行的时候它会先把符合这个条件的B表的数据取出来,这样在做外关联的话效果就没有用了。如果真要这样做的话
    Select * From(
    select a.id aid,b.id bid
      from (select t1.id from test1 t1 where t1.xh = '123') a,
           (select t2.id from test2 t2 where t2.xh = '456') b
     where a.id = b.id(+)
     
    select a.id,b.id
      from test1 a,test2 b
     where a.xh = '123'
       and a.id = b.id(+)
       ) 
       Where bid='456'