注意:
MySQL
是不支持FULL OUTER JOIN
这种语法的,因此要实现图中6、7
的查询结果,可以使用UNION
关键字结合LEFT JOIN、RIGHT JOIN
实现,UNION
可以实现去重的效果;
参考如下代码:
-- MySQL中 图标6 的实现方式
SELECT * FROM tableA A LEFT JOIN tableB B ON A.key = B.key
UNION
SELECT * FROM tableA A RIGHT JOIN tableB B ON A.key = B.key
-- MySQL中 图标7 的实现方式
SELECT * FROM tableA A LEFT JOIN tableB B ON A.key = B.key WHERE B.key IS NULL
UNION
SELECT * FROM tableA A RIGHT JOIN tableB B ON A.key = B.key WHERE A.key IS NULL
标签:JOIN,七种,UNION,tableB,tableA,key,Mysql,join,SELECT
From: https://blog.csdn.net/weixin_44666786/article/details/142024256