Inner or Outer left Join
Posted
by
user1557856
on Stack Overflow
See other posts from Stack Overflow
or by user1557856
Published on 2012-09-06T15:28:08Z
Indexed on
2012/09/06
15:38 UTC
Read the original article
Hit count: 176
I'm having difficulty modifying a script for this situation and wondering if someone maybe able to help:
I have an address
table and a phone
table both sharing the same column called id_number
. So id_number = 2
on both tables refers to the same entity. Address and phone information used to be stored in one table (the address
table) but it is now split into address
and phone
tables since we moved to Oracle 11g.
There is a 3rd table called both_ids
. This table also has an id_number
column in addition to an other_ids
column storing SSN
and some other ids.
Before the table was split into address
and phone
tables, I had this script:
(Written in Sybase)
INSERT INTO sometable_3 (
SELECT a.id_number, a.other_id,
NVL(a1.addr_type_code,0) home_addr_type_code,
NVL(a1.addr_status_code,0) home_addr_status_code,
NVL(a1.addr_pref_ind,0) home_addr_pref_ind,
NVL(a1.street1,0) home_street1,
NVL(a1.street2,0) home_street2,
NVL(a1.street3,0) home_street3,
NVL(a1.city,0) home_city,
NVL(a1.state_code,0) home_state_code,
NVL(a1.zipcode,0) home_zipcode,
NVL(a1.zip_suffix,0) home_zip_suffix,
NVL(a1.telephone_status_code,0) home_phone_status,
NVL(a1.area_code,0) home_area_code,
NVL(a1.telephone_number,0) home_phone_number,
NVL(a1.extension,0) home_phone_extension,
NVL(a1.date_modified,'') home_date_modified
FROM both_ids a, address a1
WHERE a.id_number = a1.id_number(+)
AND a1.addr_type_code = 'H');
Now that we moved to Oracle 11g, the address and phone information are split.
How can I modify the above script to generate the same result in Oracle 11g?
Do I have to first do INNER JOIN between address and phone tables and then do a LEFT OUTER JOIN to both_ids?
I tried the following and it did not work:
Insert Into..
select ...
FROM a1. address
INNER JOIN t.Phone ON a1.id_number = t.id_number
LEFT OUTER JOIN both_ids a ON a.id_number = a1.id_number
WHERE a1.adrr_type_code = 'H'
© Stack Overflow or respective owner