sytcun 发表于 2013-1-26 16:20:48

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

很易懂的例子解说
http://www.cnblogs.com/eflylab/archive/2007/06/25/794278.html

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


关于左连接、右连接、外接连总结
在9i以前可以这么写:
左联:
select a.id,a.name,b.address from a,bwhere a.id=b.id(+)
右联:
select a.id,a.name,b.address from a,bwhere 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.idwhere other_clause
右联
select a.id,a.name,b.addressfrom a right outer join b on a.id=b.idwhere other_clause
外联
select a.id,a.name,b.addressfrom a full outer join b on a.id=b.idwhere other_clauseorselect a.id,a.name,b.addressfrom a full outer join b using (id)where other_clause
页: [1]
查看完整版本: SQL 连接 JOIN 例解。(左连接,右连接,全连接,内连接,交叉连接,自连接)