内连接:
inner join 只连接2个表都有的数据
select tab1 inner join tab2 on tab1.a=tab2.b
等价于
select a,b from tab1,tab2 where tab1.a=tab2.b
外连接 有三种:
left (outer) join 左表全部数据,匹配右表,不能匹配的为空
select tab1 left (outer) join tab2 on tab1.a=tab2.b
等价于,(+)标示匹配表
select a,b from tab1,tab2 where tab1.a=tab2.b(+)
right (outer) join 右表全部数据,匹配左表,不能匹配的为空
select tab1 right(outer) join tab2 on tab1.a=tab2.b
等价于,(+)标示匹配表
select a,b from tab1,tab2 where tab1.a(+)=tab2.b
full (outer) join 右表全部数据,匹配左表全部数据,不能匹配的为空
select * from tab1 full join tab2 on tab1.a=tab2.b
总结:一般用得较多的是inner join和left join。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26249944/viewspace-743906/
,如需转载,请注明出处,否则将追究法律责任。