I use Oracle SQL, so external joins have good (+) syntax. I must warn you that I am not allowed to recycle the database; I work in a large organization.
Here are some sample tables:
People
PersonID Name
1 Elmo
2 Oscar
3 Chris
Attribute
PersonID Attribute
1 Happy
1 Muppet
1 Popular
2 Grouchy
2 Muppet
2 Popular
3 Programmer
I want a list of people, and I want to know if we have the knowledge that they are happy or grouchy. Below is the output I want:
Name Mood
Elmo Happy
Oscar Grouchy
Chris
So, here is a query that I was thinking of using:
SELECT p.Name, a.Attribute
FROM People p, Attributes a
WHERE p.PersonID = a.PersonID (+)
AND ( a.Attribute (+) = 'Happy'
OR a.Attribute (+) = 'Grouchy' )
(Perhaps I would have to put "OR a.Attribute IS NULL" or something like that.)
But actually I am not allowed to use OR inside an outer join at all! What should I do instead?
source
share