Difference between revisions of "Outer Joins"
Line 17: | Line 17: | ||
table is deficient when matching rows. (That is, it performs a combination of left and right | table is deficient when matching rows. (That is, it performs a combination of left and right | ||
outer joins.) | outer joins.) | ||
===LEFT OUTER JOIN === | |||
''' The left Outer join will provide all the customers form the customers table and if there is no order in the order table it will display as a null ''' | |||
''' This type of join returns all rows fro the LEFT hand table specified in the ON condition and ONLY those rows from the other table where teh joined fields are equal(join condition is met)''' | |||
SELECT c.lastname, c.firstname, o.order# | SELECT c.lastname, c.firstname, o.order# | ||
FROM customers c LEFT OUTER JOIN orders o | FROM customers c LEFT OUTER JOIN orders o | ||
USING (customer#) | USING (customer#) | ||
ORDER BY c.lastname, c.firstname | ORDER BY c.lastname, c.firstname | ||
A full join can’t be used with the outer join operator; it can be used only with the JOIN keyword. | A full join can’t be used with the outer join operator; it can be used only with the JOIN keyword. | ||
[[#Select Command|Back To Top]]-[[Main_Page| Home]] - [[Oracle_SQL|Category]] | [[#Select Command|Back To Top]]-[[Main_Page| Home]] - [[Oracle_SQL|Category]] |
Revision as of 14:11, 1 November 2017
An outer join is created when records needs to be included in the results without having a corresponding records in the join tables. These records are matched with the NULL records so that they are included in the output
An outer join can be created by using the WHERE clause with an outer join operator or the OUTER JOIN keywords
limitations when using the traditional approach to outer joins:
- The outer join operator can be used for only one table in the joining condition.In other words, you can’t create NULL rows in both tables at the same time.
- A condition that includes the outer join operator can’t use the IN or ORoperator.
Outer Joins: JOIN Method
When creating a traditional outer join with the outer join operator, the join can be applied to only one table—not both. However, with the JOIN keyword, you can specify which table the join should be applied to by using a left, right, or full outer join. Left and right outer joins specify which table the outer join should be applied to, based on the table’s location in the join condition. For example, a left outer join instructs Oracle to keep any rows in the table listed on the left side of the join condition, even if no matches are found with the table listed on the right. A full outer join keeps all rows from both tables in the results, no matter which table is deficient when matching rows. (That is, it performs a combination of left and right outer joins.)
LEFT OUTER JOIN
The left Outer join will provide all the customers form the customers table and if there is no order in the order table it will display as a null This type of join returns all rows fro the LEFT hand table specified in the ON condition and ONLY those rows from the other table where teh joined fields are equal(join condition is met)
SELECT c.lastname, c.firstname, o.order# FROM customers c LEFT OUTER JOIN orders o USING (customer#) ORDER BY c.lastname, c.firstname
A full join can’t be used with the outer join operator; it can be used only with the JOIN keyword.