X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 0AA01D1DB0D for ; Thu, 11 Dec 2003 22:16:43 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 23327-03 for ; Thu, 11 Dec 2003 18:16:14 -0400 (AST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id BBAC4D1D591 for ; Thu, 11 Dec 2003 18:16:11 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.10/8.12.10) with ESMTP id hBBMGC19015861; Thu, 11 Dec 2003 17:16:12 -0500 (EST) To: "Marc G. Fournier" Cc: pgsql-sql@postgresql.org Subject: Re: simple LEFT JOIN giving wrong results ... In-reply-to: <20031211165902.I17041@ganymede.hub.org> References: <20031211165902.I17041@ganymede.hub.org> Comments: In-reply-to "Marc G. Fournier" message dated "Thu, 11 Dec 2003 17:01:22 -0400" Date: Thu, 11 Dec 2003 17:16:12 -0500 Message-ID: <15860.1071180972@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200312/91 X-Sequence-Number: 16257 "Marc G. Fournier" 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