似乎select * from table1, table2,table3 where table1.id = table2.id and table1.id = table3.id和
select * from table1 inner join table2 on table1.id = table2.id
inner join table1.id = table3.id
是等价的。
我想问,怎样能在前者的情况下实现left join呢

解决方案 »

  1.   

    Left Outer Join 运算符返回满足第一个(顶端)输入与第二个(底端)输入联接的每一行。它还返回任何在第二个输入中没有匹配行的第一个输入中的行。第二个输入中的非匹配行作为空值返回。如果 Argument 列内不存在任何联接谓词,则每行都是一个匹配行。
      

  2.   


    SELECT * 
    FROM table1
    LEFT JOIN table2
    ON  table1.id = table2.id
    LEFT JOIN table3
    ON  table1.id = table3.id?
      

  3.   


    如果没有left join,就用第一种那样的形式可以吗?select * from table1,table2,table3 where .. .. . . .. --这样行吗,实现left join
      

  4.   

    declare @t1 table (id int, value int)
    insert @t1 select 1,1 union all
    select 2,2 union all
    select 3,2declare @t2 table (id int, value int)
    insert @t2 select 1,1 select * from @t1 a left join @t2 b on a.id=b.id
    (3 行受影响)(1 行受影响)
    id          value       id          value
    ----------- ----------- ----------- -----------
    1           1           1           1
    2           2           NULL        NULL
    3           2           NULL        NULL(3 行受影响)
      

  5.   

    如果不用左外连,用内联的方式可以像你这样,跟INNER JOIN等效。
      

  6.   

    我想大侠们没明白我的意思?select * from table1, table2,table3 where table1.id = table2.id and table1.id = table3.id 
    --上面的写法和下面的写法应该是一个意思,即说明上面的写法跟inner join是一样的
    select * from table1 inner join table2 on table1.id = table2.id
    inner join table1.id = table3.id而我想知道,就用上面的写法,不用这些join的关键字,怎样写出left join来???????
      

  7.   

    declare @t1 table (id int, value int)
    insert @t1 select 1,1 union all
    select 2,2 union all
    select 3,2declare @t2 table (id int, value int)
    insert @t2 select 1,1 select * from @t1 a ,@t2 b where a.id*=b.id(3 行受影响)(1 行受影响)
    id          value       id          value
    ----------- ----------- ----------- -----------
    1           1           1           1
    2           2           NULL        NULL
    3           2           NULL        NULL(3 行受影响)
      

  8.   

    SQL2K可以用楼上的写法,SQL2K5以后已不支持那种写法,楼主三思。
      

  9.   

    select * from 
    table1 a,table2 b ,table3 c 
    where  a.id *= b.id
    and a.id *= c.id
      

  10.   

    东升哥比较厉害啊!!!
    我明白了,重点是那个 "*=", "*="标识left join ,"=*"标识right join对吧!!可是执行报了个错!此查询使用的不是 ANSI 外部联接运算符("*=" 或 "=*")。若要不进行修改即运行此查询,请使用存储过程 sp_dbcmptlevel 将当前数据库的兼容级别设置为 80 或更低。极力建议使用 ANSI 外部联接运算符(LEFT OUTER JOIN、RIGHT OUTER JOIN)重写此查询。在将来的 SQL Server 版本中,即使在向后兼容模式下,也不支持非 ANSI 联接运算符。这是不是说明这种写法已经过时了???
      

  11.   

    INNER JOIN/LEFT JOIN/RIGHT JOIN/CROSS JOIN是SQL标准语法。以前那些过时的写法就没有必要再回头去找了。