13

I always tell new people that an easy way to remember the old-style, Oracle outer-join syntax is that

the (+) sign is on opposite side of where you think it should be.

Left join:

select * from foo, bar
where foo.id = bar.id(+)

Right join:

select * from foo, bar
where foo.id(+) = bar.id

I'm sure I learned this in college, but what is the purpose of having the (+) sign on either side? Does it simply indicate "even those rows on the other side that don't match on this side"? but that would seem too complicated. What was the purpose of choosing "(+)" and putting it on the side where no match was made?

Matthew Moisen
  • 16,701
  • 27
  • 128
  • 231

1 Answers1

16

The (+) identifies the table that is being outer joined to. The way I was taught, the (+) indicated the table that would have missing rows for which new NULL rows had to be added.

If you look at the alternate left outer join syntaxes that various databases supported before LEFT OUTER JOIN became part of the ANSI standard, the proprietary operator was generally applied to the table that was "missing" rows. DB2 also supports the (+) operator for outer joins in the same way that Oracle does.

Justin Cave
  • 227,342
  • 24
  • 367
  • 384
  • Would you happen to have any comment on why the "(+)" was chosen? – Matthew Moisen Mar 27 '14 at 08:07
  • 1
    Good Explanation. However, I think there is a "to" too many in "The (+) identifies the table that is being outer joined to", so the sentence is confusing. In `foo.id = bar.id(+)` bar is the table that is being outer joined, and foo is the table that (bar) is being outer joined *to*. – Thorsten Kettner Dec 12 '14 at 11:38