Oracle关联查询_join或(+)

场景1:从两个或多个表中取得数据。

select * from table1 a ,table2 b where a.id=b.id (此种写法的可读性不好,关联条件和语句的过滤条件写在一块不便于阅读)

select * from table1 a join table2 b using (id); (表之间的连接条件与表记录的筛选条件分开,可读性较好)

场景2:表1不管能不能关联上表2(不管部门是否招到人),将表1都显示出来(将部门都显示出来)。

select * from emp a right join dept b using (deptno);

归纳: left, right 是指示主表的位置。(+)号则放在附属表后面。

对等联接(关联上才显示) join a.id=b.id
左关联(左表为主表) left join a.id=b.id(+)
右关联(右表主表) right join a.id(+)=b.id
全关联(都显示) full join  

猜你喜欢

转载自yhzhangdota.iteye.com/blog/2369082
今日推荐