美文网首页
一张图看懂 SQL 的各种 join 用法

一张图看懂 SQL 的各种 join 用法

作者: packet | 来源:发表于2019-03-05 19:08 被阅读0次

从数学的角度看,是集合的操作。
比如有where语句的内连接,相当于取交集。
有的是 左连接 - 内连接
当然,这一切的前提是笛卡尔积

MySQL不支持OUTER JOIN(外连接),最下面的一行左边,但是有替代方案。

select * from table a A(A为别名)LEFT JOIN table b B on A.id=B.id
union
select * from table a A RIGHT JOIN table b B on A.id=B.id;

至于最下面一行右边

select * from table a A(A为别名)LEFT JOIN table b B on A.id=B.id
where B.id is null
union
select * from table a A RIGHT JOIN table b B on A.id=B.id
where A.id is null;

鸣谢:一张图看懂 SQL 的各种 join 用法

mysql 全外连接报错的原因

相关文章

网友评论

      本文标题:一张图看懂 SQL 的各种 join 用法

      本文链接:https://www.haomeiwen.com/subject/ghaouqtx.html