https://blog.csdn.net/lukabruce/article/details/80568796?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-2.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-2.control

全连接

两表关联,查询它们的所有记录。
全连接left join union right join - 图1
oracle里面有full join,但是在mysql中没有full join。我们可以使用union来达到目的。

  1. 1. mysql> select * from t1 left join t2 on t1.id = t2.id
  2. 2. -> union
  3. 3. -> select * from t1 right join t2 on t1.id = t2.id;
  • 全连接left join union right join - 图2

并集去交集

两表关联,取并集然后去交集。
全连接left join union right join - 图3

  1. 1. mysql> select * from t1 left join t2 on t1.id = t2.id where t2.id is null
  2. 2. -> union
  3. 3. -> select * from t1 right join t2 on t1.id = t2.id where t1.id is null;

全连接left join union right join - 图4