六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 35|回复: 0

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

[复制链接]

升级  44.67%

31

主题

31

主题

31

主题

秀才

Rank: 2

积分
117
 楼主| 发表于 2013-1-26 16:20:48 | 显示全部楼层 |阅读模式
很易懂的例子解说
http://www.cnblogs.com/eflylab/archive/2007/06/25/794278.html

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


关于左连接、右连接、外接连总结
在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.addressFROM a,bWHERE a.id = b.id(+)UNIONSELECT b.id,'' name,b.addressFROM bWHERE NOT EXISTS (SELECT * FROM aWHERE a.id = b.id);
在9i以上,已经开始支持SQL99标准,所以,以上语句可以写成:
默认内部联结:
select a.id,a.name,b.address,c.subjectfrom (a inner join b on a.id=b.id)  inner join c on b.name = c.namewhere other_clause
左联
select a.id,a.name,b.addressfrom a left outer join b on a.id=b.id  where other_clause
右联
select a.id,a.name,b.addressfrom a right outer join b on a.id=b.id  where other_clause
外联
select a.id,a.name,b.addressfrom a full outer join b on a.id=b.id  where other_clauseorselect a.id,a.name,b.addressfrom a full outer join b using (id)where other_clause
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表