两个表的结构和数据如下:
table 1 col1 clo2 col3
A B 90
A C 80
A D 70
A E 60
A F 50table 2 col4 clo5 col6
A we 100
A er 90
A rt 80
A yu 70
A oi 60
最后的结果表为:
table 3 col1 clo2 col3 clo5 col6
A B 90 we 100
A C 80 er 90
A D 70 rt 80
A E 60 yu 70
A F 50 oi 60请教高手!

解决方案 »

  1.   

    select * from
    (select rownum rn, t1.* from t1),
    (select rownum rn, t2.* from t2)
    where rn = rn;
      

  2.   

    select * from 
    table1 union all table2 on table1.col1=table2.col4
      

  3.   

    呵呵 wildwave 来了啊
    关联的话可用 col1与col4
      

  4.   

    col1,col4 关联无法满足你的要求,这两个表就没主键的么会有大量重复记录精确无法定位
      

  5.   

    shiyiwan说的对 主要是没有主键,导致产生笛卡尔积.shiyiwan的哪个语句可以得到我要的结果 呵呵 为什么我当初就没有想到呢??
      

  6.   

    好了 结帖 
    wildwave 你在这很活跃啊,看样子你工作蛮轻松的嘛
      

  7.   

    with a as
    (
    select 1 sid,'tom1' sname from dual
    union all
    select 1 sid,'tom2' sname from dual
    union all
    select 1 sid,'tom3' sname from dual
    union all
    select 1 sid,'tom4' sname from dual
    union all
    select 1 sid,'tom5' sname from dual
    union all
    select 1 sid,'tom6' sname from dual
    ),
    b as 
    (
    select 1 sid, 21 age from dual
    union all
    select 1 sid, 22 age from dual
    union all
    select 1 sid, 23 age from dual
    union all
    select 1 sid, 24 age from dual
    union all
    select 1 sid, 25 age from dual
    union all
    select 1 sid, 26 age from dual
    )
    select t.rn,max(t.sid),max(t.sname),max(t.age) from  
    (select  rownum RN, a.sid sid, a.sname, 0 age  from  a
     union   
     select     rownum RN,b.sid sid, '' sname,b.age from b) t
     group by t.rn
    解决了
      

  8.   

    结果
    1 1 tom1 21
    2 1 tom2 22
    3 1 tom3 23
    4 1 tom4 24
    5 1 tom5 25
    6 1 tom6 26