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





  • 相关阅读:
    Thinkhphp5控制器调用的Model层的方法总结
    js数组与字符串的相互转换方法
    oop中 限制文件类型和大小
    php常用内置函数
    PHP 面向对象
    微信JSSDK开发
    PHPExcel探索之旅
    php操作Excel
    百度地图和高德地图的API视频教程
    手机号码归属地查询(免费)
  • 原文地址:https://www.cnblogs.com/zhengyuan/p/9444416.html
Copyright © 2011-2022 走看看