数据库的内连接和外连接区别?
簡(jiǎn)單來(lái)講,隨便來(lái)個(gè)例子:
A表??????????????? B表
id????? name??????????? id????? name
1 a 1 b
2????????? b??????????????? 3?????? c
4????????? c
內(nèi)連接就是左表和右表相同的數(shù)據(jù):
select * from A inner join B on A.id=B.id
id????? name??????????? id????? name
1????????? a??????????????? 1?????? b
外連接分為:左外連接、右外連接、全外連接
左外連接就是以左表為準(zhǔn),去匹配右表,左表有多少條數(shù)據(jù),結(jié)果就是多少條數(shù)據(jù)
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
右外連接就是與左外連接反之,以右表為準(zhǔn),去匹配左表,右表有多少條數(shù)據(jù),結(jié)果就是多少條數(shù)據(jù)
select * from A right join B on A.id=B.id
id????? name??????????? id????? name
1????????? a??????????????? 1?????? b
null??????? null?????????????? 3?????? c
全外連接數(shù)據(jù)條數(shù)不一定,相當(dāng)與是左外連接 和右外連接 的綜合
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
轉(zhuǎn)載于:https://www.cnblogs.com/xiamiao/p/3183155.html
總結(jié)
以上是生活随笔為你收集整理的数据库的内连接和外连接区别?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 算法学习的链接(持续更新)
- 下一篇: MyEclipse 2013 新功能介绍