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

解决方案 »

  1.   

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

  2.   

    to:Petergepeter(拔刀斋) ( ) 信誉:100  2004-05-14 11:14:00  得分:0 
     
     
      select * from a,b where a.id= b.id(+)你这样的结果是a.id = b.id 再加上  a.id 当中不等于b.id 的值与空值结合的数据。所以你的结果肯定大于
        select * from a,b where b.id= a.id 选择出来是7万条。  
     
      

  3.   

    To: skystar99047(天星) ( ) 信誉:100  2004-05-14 12:21:00  得分:0 
      
      select * from b,a where b.id(+)=a.id;你得这样的结果, 是b.id=a.id的纪录。 再加上b.id (7万条)中不等于a.id的记录与空值
    结合的结果。  即, b中的记录肯定都会选中。  也就是至少是7万条记录。
      
     
      

  4.   

    使用外联接
    select * from a,outer b where a.id=b.id
      

  5.   

    select * from a,b where a.id= b.id (+)
    a表中的内容会全部显示
      

  6.   

    我理解你题意是:
    想要a表中的每一条记录与b表中的任一条记录外连接即可:我的结果是这样的,你可以试试:(我做过测试了)
    select * from a,(select * from b where rownum=1) x where a.id= x.id(+) 
    /
      

  7.   

    select * from song_main;    ID NAME
    ------ --------------------
         1 a
         2 b
         3 c select * from song_det;    ID NAME
    ------ --------------------
         1 H
         2 H
         3 H
         1 G
         2 G
         3 G
         1 F比较笨的方法!(主_从表不太了解,哈哈)
    select * from song_main a,(select id,name from (select id,name,rank() over(partition by id order by name )m from song_det)
    where m=1) b 
    where a.id=b.id(+)
    /
    其中song_main是主表,song_det是从表,楼主试试!
    每个表都只有id,name2个字段
    或许有参考价值!!
      

  8.   

    补充一下:
    刚才的我取得b表的第一条记录与a表进行外连接, 这样有可能连接后取不到b表中的纪录。
    因为b表的第一条记录的id在a表中不一定存在。重做如下:
    取a与b相等的记录中b的最大rowid。这样保证只取出一条记录。而且这条记录的id在a表里存在。
    然后用b表的这一条记录与a表作外连接:
    select * from a,(select * from b where rowid=(select max(b.rowid) from a,b where a.id=b.id )) x where a.id= x.id(+) 
    /
    得出结果 3 万条记录。
      

  9.   

    既然是主从表,那么认为a表中有记录的不一定在b表中存在,而b表中存在
    的id一定在a表存在,不然叫什么主从表。
    假设id为主键
    select a.id,max(a.col1)...,max(b.col1),max(b.col2) from a,b 
    where a.id = b.id(+) group by a.id;
    既然随便取一条,那么就取最大的一条。
    注意:如果主键有几个,需要在group by后面加。
    由于在a表中用的是主键分组,那么max(a.col1)=a.col1不影响的。
    而主从表表示a表一条记录对应b表多条记录,所以max会将其他
    记录去掉。
      

  10.   

    TO:
    snowy_howe(天下有雪)
    果然不错。
    请教:
    如果不是主从表呢?