zoukankan      html  css  js  c++  java
  • left join,inner join,right join,cross join,full join的区别

    1,总论:

    LEFT JOIN返回”first_table”中所有的行尽管在” second_table”中没有相匹配的数据。

    RIGHT JOIN返回”second_table”中所有的行尽管在”first_table”中没有相匹配的数据。

    INNER JOIN返回的结果集是两个表中所有相匹配的数据。

    没听明白?请继续看下文分解。

    2,分解:

    还是用一个例子来的痛快些。。。

    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


    cross join
    是笛卡儿乘积就是一张表的行数乘以另一张表的行数
    left join
    第一张表的连接列在第二张表中没有匹配是,第二张表中的值返回null
    right join
    第二张表的连接列在第一张表中没有匹配是,第一张表中的值返回null
    full join
    返回两张表中的行 left join+right join
    inner join
    只返回两张表连接列的匹配项


  • 相关阅读:
    100-days: twelve
    100-days: eleven
    100-days: ten
    [PKUWC 2018]随机算法
    [CTSC 2018]假面
    APIO 2018 游记
    CTSC 2018 游记
    [CQOI 2018]解锁屏幕
    [CQOI 2018]九连环
    [CQOI 2018]破解D-H协议
  • 原文地址:https://www.cnblogs.com/zhuawang/p/864972.html
Copyright © 2011-2022 走看看