| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> c.d.o.server -> Re: Conditional Join
On 26.11.2007 18:16, ErikYkema wrote:
> On Nov 25, 5:05 pm, Robert Klemme <shortcut..._at_googlemail.com> wrote:
>> On 22.11.2007 10:22, Peter wrote: >> >>> I think your outer join logic was wrong. >>> Your ANSI join syntax example should be: >>> SELECT ... >>> FROM mascustomer a RIGHT OUTER JOIN mascustaddr b >>> ON (a.customerid = b.customerid) AND (b.activeyn = 'Y') >> Shouldn't this be a LEFT outer join? From what I read in the thread >> mascustomer is the master table from which all records should be pulled. >> >> SELECT ... >> FROM mascustomer a LEFT OUTER JOIN mascustaddr b >> ON a.customerid = b.customerid AND b.activeyn = 'Y' >> >> Cheers >> >> robert
I agree with regard to the readability. However, your suggestion won't work. Your WHERE condition is too late. It will remove all columns from mascustaddr that have active = 'N' *after* the join and you will not get the proper result (i.e. too few rows). The condition must be in the join to remove active = 'N' columns before the join and leave proper NULL columns in place. Otherwise you will miss some rows from mascustomer in the result.
Kind regards
robert Received on Mon Nov 26 2007 - 14:23:38 CST
![]() |
![]() |