zoukankan      html  css  js  c++  java
  • 18mysql3

    一、内外连接全连接,左右连接

     
    █▓        通过两张表查找其对应的记录.

            隐式 内连接 select * from a,b where a.列名 = b.列名

     
    █▓        左连接

            select * from a left outer join b on a.id = b.id

     
    █▓        右连接

            select * from  a  right  outer  join b  on a.id = b.id

     
    █▓        全连接

    可以使用union来达到全外连接的查询效果。

    union :可以将左外连接查询和右外连接查询两条sql语句使用union合并起来进行查询,去掉重复的数据。

     
    select * from a left outer join b on a.id = b.id 
    union
    select * from a right outer join b on a.id = b.id
     
     
    小结

    内连接:

    1、  隐式内连接:

    Select * from a,b where a.id = b.id;

    结果:C

    2、  显示内连接:

    Select * from a inner join b on a.id = b.id;

    结果:C

     

    外连接:

    1、  左外连接

    select * from a left outer join b on a.id = b.id

    结果:A+C

    2、  右外连接

    select * from a right outer join b on a.id = b.id

    结果:B+C

    3、  union:相当于全外连接

    select * from a left outer join b on a.id = b.id

    union

    select * from a right outer join b on a.id = b.id

           结果:A+B+C,会自动虑重

     

    select * from a left outer join b on a.id = b.id

    union all

    select * from a right outer join b on a.id = b.id

    结果:A+B+C,有重复数据

    █▓
     
    █▓
     
     
    █▓
     
     
    █▓
     
    █▓
     
    █▓
     
     
    █▓
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

    <wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;">





  • 相关阅读:
    JavaScript var,let,const三个关键字的区别
    nuxt head 配置
    阿里云MySQL安装到centos,并链接。
    js Array 的所有方法
    关于手机某些字体显是不全
    关于设备与canvas画不出来的解决办法
    关于github 新工程上传代码 git 命令
    高德地图3D菱形 区域点击搜索
    高德地图行政区域划分(西安)
    vue2获取dom节点
  • 原文地址:https://www.cnblogs.com/zhengyuan/p/9444416.html
Copyright © 2011-2022 走看看