outer joins

Outer Joins

An outer join extends the result of a simple join. An outer join returns all rows that satisfy the join condition and also returns some or all of those rows from one table for which no rows from the other satisfy the join condition.

  • To write a query that performs an outer join of tables A and B and returns all rows from A (aleft outer join), use the LEFT [OUTER]JOIN syntax in the FROM clause, or apply the outer join operator (+) to all columns of B in the join condition in theWHERE clause. For all rows in A that have no matching rows in B, Oracle Database returns null for any select list expressions containing columns of B.

  • To write a query that performs an outer join of tables A and B and returns all rows from B (aright outer join), use the RIGHT [OUTER]JOIN syntax in the FROM clause, or apply the outer join operator (+) to all columns of A in the join condition in theWHERE clause. For all rows in B that have no matching rows in A, Oracle returns null for any select list expressions containing columns of A.

  • To write a query that performs an outer join and returns all rows from A and B, extended with nulls if they do not satisfy the join condition (afull outer join), use the FULL [OUTER]JOIN syntax in the FROM clause.

You cannot compare a column with a subquery in the WHERE clause of any outer join, regardless which form you specify.

 

  Using Outer Joins: Examples The following example shows how a partitioned outer join fills data gaps in rows to facilitate analytic function specification and reliable report formatting. The example first creates a small data table to be used in the join:

SELECT d.department_id, e.last_name
   FROM departments d LEFT OUTER JOIN employees e
   ON d.department_id = e.department_id
   ORDER BY d.department_id, e.last_name;

Users familiar with the traditional Oracle Database outer joins syntax will recognize the same query in this form:

SELECT d.department_id, e.last_name
   FROM departments d, employees e
   WHERE d.department_id = e.department_id(+)
   ORDER BY d.department_id, e.last_name;

我打算试试例子,但是scott没有departments这些表,于是查到

About Sample Schema HR

  The HR schema is a sample schema that can be installed as part of Oracle Database. This schema contains information about employees—their departments, locations, work histories, and related information. Like all schemas, theHR schema has tables, views, indexes, procedures, functions, and other attributes of a database schema.

The examples and tutorials in this document use the HR schema.

参考http://docs.oracle.com/cd/E11882_01/appdev.112/e10766/tdddg_intro.htm#TDDDG12400

以及如何解锁HR

ALTER USER HR ACCOUNT UNLOCK IDENTIFIED BY password;

参考:http://docs.oracle.com/cd/E11882_01/appdev.112/e10766/tdddg_connecting.htm#BABFHHCJ

这样通过例子就更快更好的理解上面outer joins的介绍了   

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值