cross join 是笛卡儿乘积 就是一张表的行数乘以另一张表的行数
left join 第一张表的连接列在第二张表中没有匹配是 , 第二张表中的值返回 null
right join 第二张表的连接列在第一张表中没有匹配是 , 第一张表中的值返回 null
full join 返回两张表中的行 left join+right join
inner join 只返回两张表连接列的匹配项
例子
declare @a table(a int,b int)
declare @b table(a int,b int)
insert @a values(1,1)
insert @a values(2,2)
insert @b values(1,1)
insert @b values(3,3)
-- 左 :
select * from @a Aa left join @b Bb on Aa.a=Bb.a
-- 右:
select * from @a Aa right join @b Bb on Aa.a=Bb.a
-- 内
select * from @a Aa join @b Bb on Aa.a=Bb.a
-- 外:
select * from @a Aa full join @b Bb on Aa.a=Bb.a
-- 完全
select * from @a,@b
-- 笛卡儿乘积
select * from @a Aa cross join @b Bb
总结
LEFT JOIN 返回”first_table”中所有的行尽管在” second_table”中没有相匹配的数据。
RIGHT JOIN 返回”second_table”中所有的行尽管在”first_table”中没有相匹配的数据。
INNER JOIN 返回的结果集是两个表中所有相匹配的数据。