Re: multiple outer joins problem

From: Gerard H. Pille <ghp_at_skynet.be>
Date: Fri, 10 Sep 2010 18:06:37 +0200
Message-ID: <4c8a578d$0$5290$ba620e4c_at_news.skynet.be>



dn.perl_at_gmail.com wrote:
> Select s.name, count(*) from t_car c, t_link l, t_state s
> Where s.name not like 't%' and s.stateid = l.stateid(+)
> And l.carid = c.carid(+) and c.month = 201008
> GROUP BY s.name
> order BY s.name;

David beat me to it, of course, since he's got nothing better to do.

Your syntax didn't provide the correct result, because the "c.month = 201008" defeats the outer join (when the c record is null, c.month is not equal to 201008, nothing is equal to null).

The old oracle outer join syntax does allow to obtain the correct result though:

Select s.name, count(*),

   sum(decode(c.month,201008,1,0))
   from t_car c, t_link l, t_state s
   Where s.name not like 't%' and s.stateid = l.stateid(+)      And l.carid = c.carid(+)
   GROUP BY s.name
   order BY s.name;

NAME                               COUNT(*) SUM(DECODE(C.MONTH,201008,1,0))
-------------------------------- ---------- -------------------------------
Arizona                                   3                               2
California                                1                               0
Delaware                                  1                               0
Florida                                   3                               3
Received on Fri Sep 10 2010 - 11:06:37 CDT

Original text of this message