zoukankan      html  css  js  c++  java
  • mysql左连接 右连接 内连接的区别

    mysql左连接 右连接 内连接的区别 

    1.内连接,显示两个表中有联系的所有数据;

    2.左链接,以左表为参照,显示所有数据,右表中没有则以null显示

    3.右链接,以右表为参照显示数据,,左表中没有则以null显示

    例子:  

    -------------------------------------------------

      a表     id   name     b表     id   job   parent_id  

                  1   张3                   1     23     1  

                  2   李四                 2     34     2  

                  3   王武                 3     34     4      

      a.id同parent_id   存在关系  

    --------------------------------------------------   

     1) 内连接  

      select   a.*,b.*   from   a   inner   join   b     on   a.id=b.parent_id      

      结果是    

      1   张3                   1     23     1  

      2   李四                  2     34     2  

       

      2)左连接  

      select   a.*,b.*   from   a   left   join   b     on   a.id=b.parent_id      

      结果是    

      1   张3                   1     23     1  

      2   李四                  2     34     2  

      3   王武                  null  

     3) 右连接  

      select   a.*,b.*   from   a   right   join   b     on   a.id=b.parent_id      

      结果是    

      1   张3                   1     23     1  

      2   李四                  2     34     2  

      null                       3     34     4  

       

     4) 完全连接  

      select   a.*,b.*   from   a   full   join   b     on   a.id=b.parent_id  

      结果是    

      1   张3                  1     23     1  

      2   李四                 2     34     2  

      null                   3     34     4  

      3   王武                 null

    连接规则

    Select (查询)tb1.*,tb2.*(信息) from(从) tb1(表1) right join(连接方式) tb2(表2) on tb1.id=tb2.pid(连接规则);

    2019-07-0623:59:19

  • 相关阅读:
    市场定位和硬件设计的错误浅谈GM8126的封装
    在Protel的机械层中如何加“机械孔”的问题
    Protel中导入导出GERBER的相关问题
    程序猿与鸡
    AltiumDesinger中Comment属性与BOM表的联系
    用CSS实现动态效果的画廊
    Two scripts work with git pull/push
    emacs中remember.el 日期乱码问题
    使用Python解压,对比文件
    Save a tree as XML using XmlSerializer
  • 原文地址:https://www.cnblogs.com/itboxue/p/11144785.html
Copyright © 2011-2022 走看看