zoukankan      html  css  js  c++  java
  • SQL 中的join

    连接(join)可分为这几种:
    左(外)连接left (outer) join,右(外)连接right (outer) join,全(外)连接full (outer) join,内关联 (inner)  join,交叉连接 cross join 。
    left (outer) join 是以左表为主表,右表为辅表,结果集为左表所有数据列,根据左右表的匹配条件,如果右表中存在匹配row,则在返回的数据集中返回匹配到的字段,否则返回null。left join比较常用,常用于基本数据表和配置信息表的匹配。比如左表是 以station为主键,其余字段为数值类型,右表也是以station为主键,其余字段是对station字段的说明信息,联合查询的时候 就可以用到left join。
    right (outer) join 与 left (outer) join 恰好相反。比较少用到。
    full(outer) join 则是 左表和右表都为主表,结果集是左表和右表所有匹配到和为匹配到的row的集合。未匹配到的字段为null。比如匹配条件为t1.station = t2.station ,左表存在station='cq',而右表中不存在,则station='cq'所在的行,t2.* 都为null,反之亦然。
    (inner) join 与左连接的区别仅仅是 返回的结果集 不包含未匹配到辅表的 row,即不存在辅表字段匹配后变成null的情况。等效于 select * from t1,t2 where t1.station = t2.station。一般来说内连接也常用。与left join相比优点是 可以过滤掉配置表中不存在的字段的数据(这种数据一般是脏数据)。
    cross join 是没有where条件的inner join,即select * from t1,t2。做笛卡儿乘。

  • 相关阅读:
    SpringBoot集成Redis
    独享锁 & 共享锁
    公平锁与非公平锁
    如何上传本地代码到码云
    SpringBoot+Mybatis+Pagehelper分页
    SpringBoot集成Mybatis(0配置注解版)
    高并发下接口幂等性解决方案
    SpringBoot全局配置文件
    干货
    Spring读取外部的资源配置文件—@PropertySource和@Value实现资源文件配置
  • 原文地址:https://www.cnblogs.com/jacktu/p/583126.html
Copyright © 2011-2022 走看看