• left join和right join和inner join


    此图仅限于理解他们之间的关系,下面还有举例,例子更好明白.

        left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 
     right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录
     inner join(等值连接) 只返回两个表中联结字段相等的行

    下图是t1和t2两张表格

    t1表格

    t2表格

    #1.
    select * from
    t1 a left join t2 b
    on a.L1 = b.L2;

    #2.
    select * from
    t2 a right join t1 b
    on a.L2 = b.L1;

    #3.
    select * from
    t2 a left join t1 b on a.L2 = b.L1;

    #4.
    select * from
    t2 a inner join t1 b
    on a.L2 = b.L1;

    #5.
    select * from
    t2 a,t1 b
    where a.L2 = b.L1;

    #6.
    select * from
    t1 a left join t2 b
    on a.L1 = b.L2
    where a.L1 = b.L2;

    #7.
    select * from
    t1 a left join t2 b
    on a.L1 = b.L2
    where a.L1 = null;

    #8.
    select * from
    t1 a left join t2 b
    on a.L1 = b.L2
    where b.L2 is null;

    #9.
    select * from
    t1 a left join t2 b
    on a.L1 = b.L2
    where b.L2 is not null;

    #10.
    select * from
    t1 a left join t2 b
    on a.L1 = b.L2
    where a.L1 = 1;

    #11.
    select * from
    t1 a left join t2 b
    on a.L1 = b.L2
    where b.L2 = 1;

  • 相关阅读:
    selenium使用
    爬取梨视频
    django实现事务
    django admin模块使用
    跨域问题和django中实现跨域
    Java多线程Condition定点通知
    Java创建线程四种方式
    JVM之JVM体系结构
    Java线程状态
    Java正则表达式解析网页源码
  • 原文地址:https://www.cnblogs.com/xinliang1788/p/11115042.html
Copyright © 2020-2023  润新知