3
Comparison types of joins in Oracle8i. Oracle9i Starting with Oracle9i, the confusing outer join syntax using the ‘(+)’ notation has been superseded by ISO 99 outer join syntax. As we know, there are three types of outer joins, left, right, and full outer join. The purpose of an outer join is to include non-matching rows, and the outer join returns these missing columns as NULL values. Let’s review the syntax differences between these variations in join syntax: Left outer join: Oracle8i Select last_name, department_name from employees e, departments d where e.department_id = d.department_id(+); Left outer join: Oracle9i Select last_name, department_name from employees e left outer join departments d on e.department_id = d.department_id; Right outer join: Oracle8i Select last_name, department_name from employees e, departments d where e.department_id(+) = d.department_id; Right outer join: Oracle9i

8i Vs 9i Oracle Joins

Embed Size (px)

DESCRIPTION

8i Vs 9i Oracle Joins Assignment

Citation preview

Page 1: 8i Vs 9i Oracle Joins

Comparison types of joins in Oracle8i. Oracle9i

Starting with Oracle9i, the confusing outer join syntax using the ‘(+)’ notation has been superseded by ISO 99 outer join syntax. As we know, there are three types of outer joins, left, right, and full outer join. The purpose of an outer join is to include non-matching rows, and the outer join returns these missing columns as NULL values.

Let’s review the syntax differences between these variations in join syntax:

Left outer join: Oracle8i

Select last_name, department_namefrom employees e, departments dwhere e.department_id = d.department_id(+);

Left outer join: Oracle9i

Select last_name, department_namefrom employees eleft outer join departments don e.department_id = d.department_id;

Right outer join: Oracle8i

Select last_name, department_namefrom employees e, departments dwhere e.department_id(+) = d.department_id;

Right outer join: Oracle9i

Select last_name, department_namefrom employees eright outer join departments don e.department_id = d.department_id;

Page 2: 8i Vs 9i Oracle Joins

Note that tblPosts includes a record for a userID that either has not been created or has been deleted. This will be important later. In my examples, I show SQL for Oracle 8i and 9i. The 8i queries should work in 9i, but it wasn't until 9i that joins were ANSI compliant in Oracle. So, the 9i queries will not work in 8i.

An inner join returns rows from two tables where there are rows in both tables that meet the join criteria.

Inner join: Oracle8i

Select last_name, department_namefrom employees e, departments dwhere e.department_id = d.department_id;

Inner join: Oracle9i

Select last_name, department_namefrom employees einner join departments don e.department_id = d.department_id;

Note that now all rows in both tables are accounted for. It is possible to get the same results in Oracle 8i using the following syntax:

Full outer join: Oracle8i

Select last_name, department_namefrom employees e, departments dwhere e.department_id(+) = d.department_id;UnionSelect last_name, department_namefrom employees e, departments dwhere e.department_id = d.department_id(+);

The union essentially joins the two join statements. In 8i this must be done because the (+) operator is unidirectional and will throw an error if you try to apply it to both criteria of the join. This query should give you the same results as a full outer join.

Page 3: 8i Vs 9i Oracle Joins

There is also a full outer join. Full outer joins became available in Oracle9i. If you are running an earlier version of Oracle you will not be able to run this code. A full outer join will get rows from tables regardless of whether there is a match either way. This is a bidirectional join.

Full outer join: Oracle9i

Select last_name, department_namefrom employees efull outer join departments don e.department_id = d.department_id;