A:  
ID  name  
1    a1    
2    a2  
 
B:  
ID  name  
1    b1  
2    b2  
3    b3  
 
结果  
ID  A.name  b.name  
1    a1              b1  
2    a2              b2  
3    null          b3  
 
如果出现  A  表数据比      b    表多,也能全部抓出来  
 
我的写法  
select  *  from  a  left  join  b  
on  a.id  =  b.id  
 
union  
 
select  *  from  b  left  join  a  
on  a.id  =  b.id  
总是觉得这么写不太好,各位大大哪个有更加精妙的写法

解决方案 »

  1.   

    select * from a right join b on a.id = b.id
      

  2.   

    如果是9i以上的可以用full outer join。select * from a full outer join b on a.id = b.id
      

  3.   

    select * from a full outer join b on a.id = b.id
      

  4.   

    可能是最快的方法
    select a.id,a.name,b.name from a,b where a.id=b.id
    union
    select a.id,a.name,'' from a where not exists(select 1 from b where a.id=b.id)
    union
    select b.id,b.name,'' from b where not exists(select 1 from a where a.id=b.id)
      

  5.   

    select * from a,b where a.id(+) = b.id