SQL 连接 JOIN 例解。(左连接,右连接,全连接,内连接,交叉连接,自连接)...

[color=red]很易懂的例子解说[/color]
[url]http://www.cnblogs.com/eflylab/archive/2007/06/25/794278.html[/url]

右连接,等号右侧的所有记录都会显示,无论在左侧是否得到匹配


关于左连接、右连接、外接连总结
在9i以前可以这么写:
左联:
select a.id,a.name,b.address from a,b  
where a.id=b.id(+)

右联:
select a.id,a.name,b.address from a,b  
where a.id(+)=b.id

外联
SELECT a.id,a.name,b.address
FROM a,b
WHERE a.id = b.id(+)
UNION
SELECT b.id,'' name,b.address
FROM b
WHERE NOT EXISTS (
SELECT * FROM a
WHERE a.id = b.id);

在9i以上,已经开始支持SQL99标准,所以,以上语句可以写成:
默认内部联结:
select a.id,a.name,b.address,c.subject
from (a inner join b on a.id=b.id)
inner join c on b.name = c.name
where other_clause

左联
select a.id,a.name,b.address
from a left outer join b on a.id=b.id
where other_clause

右联
select a.id,a.name,b.address
from a right outer join b on a.id=b.id
where other_clause

外联
select a.id,a.name,b.address
from a full outer join b on a.id=b.id
where other_clause
or
select a.id,a.name,b.address
from a full outer join b using (id)
where other_clause
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值