I have a table which stores five important facts about a user:
ID (number)
First Name
Last Name
Type
Change_Indicator
The system, for some reason, stores maiden names of the female people in this table as well except the type = ‘ALMD’.
So, if I wanted to get a person’s maiden name I go:
SELECT Last_Name FROM person WHERE type = ‘ALMD’ and ID = 1234
Every time a person changes his or her details (any part of the name, etc.) a new row is inserted into the table and the old rows have a change_indicator flag set to ‘Y’.
So, if I have changed my name before and I want to get my latest record, I do:
SELECT * FROM person WHERE change_indicator IS NULL and ID = 12345
As a side note, the change_indicator for a maiden name is set to (something) (or other words NOT NULL).
The query I’m trying is to get all users and, if applicable, their maiden name.
Sounds like a perfect candidate for a self outer join, right?
Here is what I have:
Code:
SELECT
s.first_name,
s.last_name as married_name,
m.last_name as maiden_name
FROM
person s,
person m
WHERE
s.change_indicator is null
and s.id = m.id(+)
and m.type_code = 'ALMD'
and s.last_name != m.last_name
The last little s.last_name != m.last_name is because there can be duplicates (say if someone was once married and is now divorced their maiden name will match their last name, etc.).
Ok, there’s something wrong with that query. It’s not doing an outer join. Only women with maiden names are selected. Assuming the query is correct I think it has something to do with the way Oracle 8i handles the join parameters, but I can’t find anything online to tell me what to look for.
Help?
