数据库的内连接和外连接区别?

简单来讲,随便来个例子:
A表                B表
id      name            id      name
1 a 1 b
2          b                3       c
4          c
内连接就是左表和右表相同的数据:
select * from A inner join B on A.id=B.id
id      name            id      name
1          a                1       b
外连接分为:左外连接、右外连接、全外连接
左外连接就是以左表为准,去匹配右表,左表有多少条数据,结果就是多少条数据
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

posted @ 2013-07-11 01:11  夏淼  阅读(557)  评论(0编辑  收藏  举报