半夏微凉

半夏微凉

Oracle内连接、自连接、外连接、右外连接、全外连接总结

内连接:即最常见的等值连接。

左外连接:(left outer join 或者 left join)左外连接就是在等值连接的基础上加上主表中的未匹配数据。

右外连接:(right outer join 或者 right join)右外连接是在等值连接的基础上加上被连接表的不匹配数据。

全外连接:(full join)全外连接是在等值连接的基础上将左表和右表的未匹配数据都加上。

自连接:把一张表当成两张表用,可以得到一些特殊的数据。


内连接

即最常见的等值连接,表示两个或多个表连接查询。


----内连接

select * from t_a,t_b where t_a.type=t_b.typeid;

Oracle内连接、自连接、外连接、右外连接、全外连接总结 数据库 第1张

左外连接

左外连接就是在等值连接的基础上加上主表中的未匹配数据。


----左外连接(left outer join 或者 left join)

select * from t_a left outer join t_b on  t_a.type=t_b.typeid;

select * from t_a,t_b where t_a.type=t_b.typeid(+);

Oracle内连接、自连接、外连接、右外连接、全外连接总结 数据库 第2张

----三张表的左外连接

select * from t_a left join t_b on  t_a.type=t_b.typeid left join t_c on t_a.type=t_c.id;

select * from t_a,t_b,t_c where t_a.type=t_b.typeid(+) and t_a.type=t_c.id(+);

Oracle内连接、自连接、外连接、右外连接、全外连接总结 数据库 第3张

右外连接

右外连接是在等值连接的基础上加上被连接表的不匹配数据。


----右外连接(rihgt outer join 或者 right join)

select * from t_a right join t_b on t_a.type=t_b.typeid;

select * from t_a,t_b where t_a.type(+)=t_b.typeid;

Oracle内连接、自连接、外连接、右外连接、全外连接总结 数据库 第4张

全外连接

全外连接是在等值连接的基础上将左表和右表的未匹配数据都加上。


----全外连接(full join)

select * from t_a full join t_b on t_a.type=t_b.typeid full join t_c on t_a.type=t_c.id;

Oracle内连接、自连接、外连接、右外连接、全外连接总结 数据库 第5张

自连接

----自连接(把一张表当成两经表用,可以得到一些特殊的数据)

select a.name,a.shuliang,b.name,b.shuliang,a.jiage from t_a a,t_a b where a.name<>b.name and a.jiage=b.jiage and a.rowid<b.rowid; 

Oracle内连接、自连接、外连接、右外连接、全外连接总结 数据库 第6张

评论回复


·