zoukankan      html  css  js  c++  java
  • MySQL数据库之多表查询right join右外连接

    右外连接

    • 规则

      • 以右边的表为准,左边如果没有对应的记录用null显示
    • 语法

      • select * from 表1 right join 表2 on 表1.公共字段=表2.公共字段
    MariaDB [sel]> select math,id from grades right join resume on grades.name=resume.name;
    +------+----+
    | math | id |
    +------+----+
    |   96 |  1 |
    |   91 |  3 |
    | NULL |  2 |
    +------+----+
    # `3 rows in set (0.001 sec)`
    
    MariaDB [sel]> select math,id from resume right join grades on grades.name=resume.name;
    +------+------+
    | math | id   |
    +------+------+
    |   96 |    1 |
    |   91 |    3 |
    |   94 | NULL |
    |   94 | NULL |
    +------+------+
    # `4 rows in set (0.000 sec)`
    
    • 思考
      • select * from 表1 left join 表2 on 表1.公共字段=表2.公共字段select * from 表2 right join 表1 on 表1.公共字段=表2.公共字段 一样吗?
      • 答:一样
  • 相关阅读:
    uoj 36 玛里苟斯
    readlink
    Endless Spin
    rm
    rmdir
    [学习笔记]min-max容斥
    cp
    [HAOI2015]按位或
    java实现第四届蓝桥杯公式求值
    java实现第四届蓝桥杯危险系数
  • 原文地址:https://www.cnblogs.com/SharkJiao/p/14137835.html
Copyright © 2011-2022 走看看