zoukankan      html  css  js  c++  java
  • left ,right ,cross ,full/left outer join/区别 详解

    --创建测试表ww
    if OBJECT_ID('qq') is not null drop table qq
    create table qq([序号] varchar(5),[内容1] varchar(10),[内容2] varchar(15))
    insert into qq([序号],[内容1],[内容2])
    select 'dd','zoumin','yuzulin'
    union all
    select 'cc','zm','yz'
    union all
    select 'AA','z1','yz1'
    union all
    select 'BB','zm2','yz2'
    select * from qq
    drop table qq

    --创建测试表 ww

    if OBJECT_ID('ww') is not null drop table ww
    create table ww([序号] varchar(5),[内容1] varchar(10),[内容2] varchar(15))
    insert into ww([序号],[内容1],[内容2])
    select 'ee','ee','rr'
    union all
    select 'ff','tt','yy'
    union all
    select 'AA','tt1','yy1'
    union all
    select 'BB','tt1','yy1'
    select * from ww
    drop table ww


    --内连接(inner可省)
    select * from qq inner join ww on qq.序号=ww.序号
    --On 条件可变得内连接
    select * from qq inner join ww on qq.序号!=ww.序号
    --交叉连接(加where 条件后=inner join)
    select * from qq cross join ww where qq.序号=ww.序号

    --交叉连接(逗号形式的)
    select * from qq , ww where qq.序号=ww.序号
    --左连接
    select * from qq left join ww on qq.序号=ww.序号
    --做外连接=左连接
    select * from qq left outer join ww on qq.序号=ww.序号
    --右连接
    select * from qq right join ww on qq.序号=ww.序号
    --全连接=left+right
    select * from qq full join ww on qq.序号=ww.序号

  • 相关阅读:
    Resharper Visual studio中的插件
    MVC 中Simditor上传本地图片
    MVC编程模型
    数据库面试题
    SQL、索引
    存储过程详解
    EF的简单认识
    MVC是什么
    AOP面向切面编程
    SQL语句基本
  • 原文地址:https://www.cnblogs.com/zoumin123/p/4922180.html
Copyright © 2011-2022 走看看