« MidpSSH | Main | Optimistic locking with Oracle 10 »

August 10, 2005

Oracle outer join with multiple fields

I don't know why but I always thought that outer joining with multiple fields are not going to work. So when I had to do one today I decided to give it a test.

Say a simple table


parent
{ p_id number,
account_num varchar2(10),
account_type number
}

and


child
{ c_id number,
account_num varchar2(10),
account_type number
}

and we need to join where both the account_num and account_type is the same if they exist on the child table, if the child record does not exist still include the parent record. The query is simply:


select *
from parent p, child c
where p.account_num = c.account_num(+)
and p.account_type = c.account_type(+)

It's so simple I didn't think it was going to work initially :)

Posted by vhadiant at August 10, 2005 11:11 PM





Trackback Pings

TrackBack URL for this entry:
http://www.hadianto.net/mov32/mt-tb.cgi/89

Comments

Post a comment





Remember Me?

(you may use HTML tags for style)