X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id A2DDB52ACB for ; Wed, 17 Aug 2005 17:55:14 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 55301-02 for ; Wed, 17 Aug 2005 20:55:09 +0000 (GMT) Received: from priv-edtnes51.telusplanet.net (outbound04.telus.net [199.185.220.223]) by svr1.postgresql.org (Postfix) with ESMTP id 09006529C2 for ; Wed, 17 Aug 2005 17:55:07 -0300 (ADT) Received: from localhost ([199.185.220.240]) by priv-edtnes51.telusplanet.net (InterMail vM.6.01.04.04 201-2131-118-104-20050224) with ESMTP id <20050817205509.AVV27125.priv-edtnes51.telusplanet.net@localhost> for ; Wed, 17 Aug 2005 14:55:09 -0600 Received: from 209.17.183.249 ( [209.17.183.249]) as user a3a18850@192.168.200.1 by webmail.telus.net with HTTP; Wed, 17 Aug 2005 13:55:09 -0700 Message-ID: <1124312109.4303a42d88b93@webmail.telus.net> Date: Wed, 17 Aug 2005 13:55:09 -0700 From: Mischa Sandberg To: pgsql-sql@postgresql.org Subject: Re: Is it This Join Condition Do-Able? Ooh, ouch, blush References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit User-Agent: Internet Messaging Program (IMP) 3.1-cvs X-Originating-IP: 209.17.183.249 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.056 required=5 tests=[AWL=-0.370, DNS_FROM_RFC_POST=1.376, FORGED_RCVD_HELO=0.05] X-Spam-Level: * X-Archive-Number: 200508/133 X-Sequence-Number: 22361 The Subject says it all. (author beats a hasty retreat). Quoting Dmitri Bichko : > I don't see what the problem is. > Did you mean to insert (3,'C3') into table c, rather than b? > > create temp table a(keyf int, val text); > > create temp table b(keyf int, val text); > > create temp table c(keyf int, val text); > > insert into a values(1, 'A1'); > > insert into a values(2, 'A2'); > > insert into a values(3, 'A3'); > > insert into a values(4, 'A4'); > > insert into b values(1, 'B1'); > > insert into b values(2, 'B2'); > > insert into c values(2, 'C2'); > > insert into b values(3, 'C3'); > > select keyf, a.val as aval, > > coalesce(b.val,'Bxx') as bval, > > coalesce(c.val,'Cxx') as cval > > from a left join b using(keyf) left join c using (keyf); > > keyf aval bval cval > > ---- ---- ---- ---- > > 1 A1 B1 Cxx > > 2 A2 B2 C2 > > 3 A3 C3 Cxx > > 4 A4 Bxx Cxx