I am trying to create a left inner join on a linking table to pull back each record in a PERSON table along with its one-and-only correlating "primary" phone number (indicated by a primary_indicator field on the TELEPHONE table). If the PERSON record does not have a "pimary" phone I want to return null values for the phone number. But my resuts only pull back PERSON records that have a "primary" phone. My table structure is as follows (with three tables):
PERSON
- id
- last_name
PERSON_TELEPHONE (this is the linking table)
- person_id
- telephone_id
TELELPHONE
- phone_number
- primary_indicator (where '1' = true)
My sql is as follows:
SELECT A.LAST_NAME,C.PHONE_NUMBER
FROM PERSON A LEFT OUTER JOIN PERSON_TELEPHONE B
ON A.PERSON_ID = B.PERSON_ID
JOIN TELEPHONE C
ON B.TELEPHONE_ID = c.TELEPHONE_ID
WHERE C.PRIMARY_INDICATOR = '1'
I think my problem has something to do with not having an inner join on the C.PRIMARY_INDICATOR column (in old-school sql this would be indicated by (+)). I am not sure how this is done in ANSI though.
I do not have permissions to create a temp table in the database.
PERSON
- id
- last_name
PERSON_TELEPHONE (this is the linking table)
- person_id
- telephone_id
TELELPHONE
- phone_number
- primary_indicator (where '1' = true)
My sql is as follows:
SELECT A.LAST_NAME,C.PHONE_NUMBER
FROM PERSON A LEFT OUTER JOIN PERSON_TELEPHONE B
ON A.PERSON_ID = B.PERSON_ID
JOIN TELEPHONE C
ON B.TELEPHONE_ID = c.TELEPHONE_ID
WHERE C.PRIMARY_INDICATOR = '1'
I think my problem has something to do with not having an inner join on the C.PRIMARY_INDICATOR column (in old-school sql this would be indicated by (+)). I am not sure how this is done in ANSI though.
I do not have permissions to create a temp table in the database.