• 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;">





  • 相关阅读:
    清除 Windows 系统垃圾的 bat
    java通过System.getProperty获取系统属性
    【转】Angular之constructor和ngOnInit差异及适用场景
    p中不能包含div
    How to make PostgreSQL functions atomic?
    How to chain a command after sudo su?
    javascript柯里化
    如何在Angular优雅编写HTTP请求
    angular default project (angular.json的解读)
    error:crosses initialization of ...的解决办法
  • 原文地址:https://www.cnblogs.com/zhengyuan/p/9444416.html
Copyright © 2020-2023  润新知