Re: simple LEFT JOIN giving wrong results ... - Mailing list pgsql-sql

From Tom Lane
Subject Re: simple LEFT JOIN giving wrong results ...
Date
Msg-id 15860.1071180972@sss.pgh.pa.us
Whole thread Raw
In response to simple LEFT JOIN giving wrong results ...  ("Marc G. Fournier" <scrappy@hub.org>)
Responses Re: simple LEFT JOIN giving wrong results ...  ("Marc G. Fournier" <scrappy@postgresql.org>)
List pgsql-sql
"Marc G. Fournier" <scrappy@hub.org> writes:
> So, I'm doing my LEFT JOIN wrong *somehow*, but its eluding me as to
> what/how .. :(

> ams=# select ct.ip_id, sum(ct.bytes) as traffic,
>              avg(cs.bytes)::bigint as storage
>         from company_00186.traffic ct
>    left join company_00186.storage cs ON ( ct.ip_id = cs.ip_id AND
>                                            month_trunc(cs.runtime) = '2003-12-01')
>        where month_trunc(ct.runtime) = '2003-12-01' group by ct.ip_id;

I suspect you do not want the month_trunc constraint to be included
in the JOIN ON condition, only in WHERE.
        regards, tom lane


pgsql-sql by date:

Previous
From: "Marc G. Fournier"
Date:
Subject: simple LEFT JOIN giving wrong results ...
Next
From: "Marc G. Fournier"
Date:
Subject: Re: simple LEFT JOIN giving wrong results ...