例如:SELECT * 
FROM 
t1 LEFT JOIN t2 ON t1.i=t2.i
LEFT JOIN t3 on t1.i=t3.i语句2:
SELECT * 
FROM 
t1 LEFT JOIN 
t2 LEFT JOIN t3 on t2.i=t3.i
 ON t1.i=t2.i
结果是否一定一样,能不能举出反例??

解决方案 »

  1.   

    if object_id('t1') is not null
    drop table t1
    go
    create table t1(i varchar(10),  分值 int)
    insert t1
    select 'a',100
    union all
    select 'b',90
    union all
    select null,80
    union all
    select 'd',70
    union all
    select 'e',60
    union all
    select 'f',50if object_id('t2') is not null
    drop table t2
    go
    create table t2(i varchar(10),  年龄 int)
    insert t2
    select 'a',23
    union all
    select 'b',24
    union all
    select 'c',25
    union all
    select null,22
    union all
    select 'e',23
    go
    if object_id('t3') is not null
    drop table t3
    go
    create table t3(i varchar(10),  身高 int)
    insert t3
    select 'a',161
    union all
    select 'b',167
    union all
    select 'c',172
    union all
    select 'e',180
    union all
    select 'h',160
    SELECT * 
    FROM 
    t1 LEFT JOIN t2 ON t1.i=t2.i
    LEFT JOIN t3 on t1.i=t3.i
    go
    SELECT * 
    FROM 
    t1 LEFT JOIN 
    t2 LEFT JOIN t3 on t2.i=t3.i
     ON t1.i=t2.i
      

  2.   

    a外连接b外连接c是否=a外连接(b外连接c)
    求教!!!!!!!
      

  3.   

    外连接的执行顺序
    a,执行笛卡儿积
    b,执行‘on’后面的条件的语句
    c,补NULL
    d.执行‘WHERE’后面的条件的语句
      

  4.   

    你语句1后加个where条件,语句2后也加个where条件看看。
      

  5.   

    顶搂主的研究精神想了下,结合律是有一定道理的,对于单向的(全部left join),应该是成立的,个人观点
      

  6.   

    不能完全这么看 主要看你的连接条件 
    t1(id,name)  t2(id,name)  t3(id,name)t1先连接t2   t2部分name变成了null 再用name去连接t3 显然连接不到了
    要是先用 t2 的name去连接t3 那么这个连接是有效的
      

  7.   

    有效又怎么样呢,再用t2连接t2与t3连接的结果时,照样得到NULL
      

  8.   

    这种是相等的 但是 你的第二种写法是 
    a外连接(b外连接c)
    是这个意思吗 
      

  9.   

    ------------------------------
    是啊,答案是外连接不符合结合律(还记得小学的结合律吗),即(a外连接b)外连接c  不等于  
    a外连接(b外连接c),让举一个反例,我想不出来!
      

  10.   

    t1(id) t2(id) t3(id)
    t1 
    1   2  3 
    t2
    1  1  3  3 
    t3
    2  4方案一:a外连接b外连接c
    a外连接b:
    得到 1 1 2 3 3
    再外链c
    还是   1 1 2 3 3   但是 t3中 2所对应的值 最终是能够取到的
    方案二:a外链(b外连接c )
    b外连接c
    得到: 1 1 3 3 
    此时注意了 t3中 2所对应的值成null了
    a外链 上面生成的结果
    得到的id还是 1 1 2 3 3 
    希望楼主能够理解
      

  11.   

    t1(id,name) t2(id,name) t3(id,name)
    t1 
    1,a
    2,b
    3,c
    t2
    1,x
    3,d
    t3
    2,y按照这个数据 楼主可以测试一下  我这边没测试环境