表T2中,主键是由A与B两个字段组成SELECT * FROM T1,T2 WHERE T1.A=T2.A   AND  T1.B=T2.BSELECT * FROM T1,T2 WHERE T1.A=T2.A   AND  T1.B=T2.B(+)这两个语句检索的结果集怎么能是一样的呢?为什么?
先谢谢了!

解决方案 »

  1.   

    我这里没有ORACLE 环境,我给你用SQL岩石一下区别,等5分钟
      

  2.   

    create table t1(id int identity(1,1), cname nvarchar(20))
    insert into t1 select 'a'
         union all select 'b'
         union all select 'c'
         union all select 'd'
         union all select 'e'
    create table t2(id int identity(1,1), cname nvarchar(20))
    insert into t2 select 'q'
         union all select 'w'
         union all select 'e'
         union all select 'r'select t1.id,t1.cname,t2.cname from t1
    inner join t2 on t1.id=t2.id
    --因为t2只有4条纪录,所以返回4条纪录
    ----------------
    1 a q
    2 b w
    3 c e
    4 d rselect t1.id,t1.cname,t2.cname from t1
    right  join t2 on t1.id=t2.id
    --右连接,因为右边的表t2只有4条,所以返回4条
    ----------------
    1 a q
    2 b w
    3 c e
    4 d rselect t1.id,t1.cname,t2.cname from t1
    left  join t2 on t1.id=t2.id--右连接,因为左边的表t1有5条纪录,所以返回5条
    ------
    1 a q
    2 b w
    3 c e
    4 d r
    5 e NULLselect t1.id,t1.cname,t2.cname from t1
    full outer  join t2 on t1.id=t2.id
    --包含全部,因为最多的是5条,所以返回5条
    ---------------
    1 a q
    2 b w
    3 c e
    4 d r
    5 e NULL
    Oracle里面的左右连接一样道理。