<join_type>指定联接操作的类型。INNER指定返回每对匹配的行。废弃两个表中不匹配的行。如果未指定联接类型,则这是默认设置。FULL [OUTER]指定在结果集中包含左表或右表中不满足联接条件的行,并将对应于另一个表的输出列设为 NULL。这是对通常由 INNER JOIN 返回的所有行的补充。说明  按此处指定的方法指定外联接或在 WHERE 子句中使用旧式非标准的 *= 和 =* 运算符都是可行的。不能在同一语句中同时使用这两种方法。
LEFT [OUTER]指定在结果集中包含左表中所有不满足联接条件的行,且在由内联接返回所有的行之外,将另外一个表的输出列设为 NULL。RIGHT [OUTER]指定在结果集中包含右表中所有不满足联接条件的行,且在由内联接返回的所有行之外,将与另外一个表对应的输出列设为 NULL。

解决方案 »

  1.   

    给你一个例子,自己看看效果就知道了
    if object_id('tempdb..#temp1') is not null drop table #temp1
    if object_id('tempdb..#temp2') is not null drop table #temp2select 1 as Id, 'a' as name
    into #temp1
    union select 2, 'b'
    union select 4, 'd'
    union select 5, 'e'
    union select 6, 'f'select * from #temp1select 'a' as name, 1 as number
    into #temp2
    union select 'b', 2
    union select 'c', 3
    union select 'e', 5
    union select 'f', 6select * from #temp2select a.Id, a.name, b.name, b.number from #temp1 a join #temp2 b on a.name = b.name
    select a.Id, a.name, b.name, b.number from #temp1 a left join #temp2 b on a.name = b.name
    select a.Id, a.name, b.name, b.number from #temp1 a right join #temp2 b on a.name = b.name
    select a.Id, a.name, b.name, b.number from #temp1 a full join #temp2 b on a.name = b.namedrop table #temp1
    drop table #temp2