• MySQL中join的7种方法


    join查询的7中方法

    • 手写顺序:

      SELECT DISTINCT
      	<select_list>
      FROM
      	<left_table> <join_type>
      JOIN <right_table> ON <join_condition>
      WHERE
      	<where_condition>
      GROUP BY
      	<group_by_list>
      HAVING
      	<having_condition>
      ORDER BY
      	<order_by_condition>
      LIMIT <limit_number>
      
    • MySQL执行顺序

      FROM <left_table>
      ON <join_condition>
      <join_type> JOIN <right_table>
      WHERE <where_condition>
      GROUP BY <group_by_list>
      HAVING <having_condition>
      DISTINCT <select_list>
      ORDER BY <order_by_condition>
      LIMIT <limit_number>
      

    • join连接方式:

      • 内连接:

     SELECT <select_list> FROM TableA A INNER JOIN TableB B ON A.Key = B.Key
    
    • 左连接:

     SELECT <select_list> FROM TableA A LEFT JOIN TableB B ON A.Key = B.Key
    
    • 右连接:

     SELECT <select_list> FROM TableA A RIGHT JOIN TableB B ON A.Key = B.Key
    
    • 只有A

      SELECT <select_list> FROM TableA A LEFT JOIN TableB B ON A.Key = B.Key WHERE B.Key IS NULL
    
    • 只有B

        SELECT <select_list> FROM TableA A RIGHT JOIN TableB B ON A.Key = B.Key WHERE A.Key IS NULL
    
    • 全连接

        # MySQL没有FULL OUTER语法。
        SELECT <select_list> FROM TableA A LEFT JOIN TableB B ON A.Key = B.Key
        union
        SELECT <select_list> FROM TableA A RIGHT JOIN TableB B ON A.Key = B.Key;
    
    • A,B各自独有:


      # MySQL没有FULL OUTER语法。
      SELECT <select_list> FROM TableA A LEFT JOIN TableB B ON A.Key = B.Key WHERE B.Key IS NULL
      union
      SELECT <select_list> FROM TableA A RIGHT JOIN TableB B ON A.Key = B.Key WHERE A.Key IS NULL;
    
  • 相关阅读:
    OAuth2.0协议流程
    记多个微服务同时被kill分析
    记一次调用API遇到的问题
    win10安装mysql遇到的坑
    nagios
    rmp安装mysql5.6
    桥接模式-xshell连接虚拟机
    VMWare虚拟机-网络适配器
    ***时间目录***
    docker常用命令
  • 原文地址:https://www.cnblogs.com/xujunkai/p/12491195.html
Copyright © 2020-2023  润新知