SQL左链接、右链接、全链接的区别

外连接分为:左外连接、右外连接、全外连接
左外连接就是以左表为准,去匹配右表,左表有多少条数据,结果就是多少条数据
select * from A left join B on A.id=B.id
id name id name
1 a 1 b
2 b null null
4 c null null
右外连接就是与左外连接反之,以右表为准,去匹配左表,右表有多少条数据,结果就是多少条数据
select * from A right join B on A.id=B.id
id name id name
1 a 1 b
null null 3 c
全外连接数据条数不一定,相当与是左外连接 和右外连接 的综合
select * from A full join B on A.id=B.id
id name id name
1 a 1 b
2 b null null
null null 3 c
4 c null null
原文地址:https://www.cnblogs.com/huhuiliang/p/4344417.html