SQL—— JOIN

一张图搞定:

  1. 内连接
    1. join 即 inner join
    2. 交叉连接 cross join(笛卡尔积)
      1. 隐式连接:select * from A,B where A.a='1';(没有on xxxx 的条件
      2. 显式链接:select * from A cross join B where A.a='1';
    3. 逗号表示法
      1. select * from A,B on A.a=B.a;
  2. 外连接
    1. 左外连接 即 左连接left join:表示主表是左边这张表,左边不取空。
      1. 如A left join B,表示A表连接上B表,A是主表。
    2. 右外连接 即 右连接right join:表示主表是右边的这张表,右边不取空。
      1. 如A right join B,表示A表连接上B表,但B是主表。
  3. 连接的其他表示方法
    1. (+)运算符:
      哪个表后面跟了(+),哪个表就是匹配表,另一个表是基础表。
      如:select * from A,B where A.a=B.b(+)   --- 左连接
    2. 逗号
      相当于inner join。

猜你喜欢

转载自blog.csdn.net/Jinandawang/article/details/129131644