Outer join of more than two tables

by Irina 30. March 2009 05:46

Multi-table joins have the following requirements:

  • Only two tables may be joined at a time
  • Each Join must have an associated
  • On clause placement must associate the two tables being joined

 

Example

 Select information.customer_id

          customer_name,

          custom_adress

from customer_information information right outer join

campaign_new_year campaign

on   information.customer_id = campaign.customer_id

left outer join job j

on campaign.customer_id = j.customer_id

 

The placement on the ON clause in the select is important. The rules are:

  • The first On clause (from left to right) is evaluated first
  • AN On clause applies to immediately preceding operations

 

When defining 3 or more tables in outer join operations you must consider the results of each separated join operation as a derived or temporary table

 

Example:  

 

Select * from

  (

(Select information.customer_id

          customer_name,

          custom_adress

from customer_information information right outer join

campaign_new_year campaign

on  information.customer_id = campaign.customer_id) result

left outer join job j

on result.customer_id = j.customer_id) a

 

 

About the author

Irina Spivak Irina Spivak
Team Leader at G-Stat. More...


Send mail Email

Authors

Blogroll

    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2010

    Sign in

    eXTReMe Tracker