X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 5A7199FA5CD for ; Sat, 1 Jul 2006 18:44:52 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 76957-02 for ; Sat, 1 Jul 2006 18:44:47 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from web31805.mail.mud.yahoo.com (web31805.mail.mud.yahoo.com [68.142.207.68]) by postgresql.org (Postfix) with SMTP id EE4E99FA5C3 for ; Sat, 1 Jul 2006 18:44:46 -0300 (ADT) Received: (qmail 36618 invoked by uid 60001); 1 Jul 2006 21:44:45 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=FwtfdFNpB+N0t9ODwQLmsUxMyQZ1oEf18Ua3kNMOb84/wqKqkaZcw48ECgVw9iatFlwDVcmjJt80EbzqbzY6rlgCGSBNBGDdFoY0UjceuYisoTDlGrOkgndItEl7C/2Mhc/LzXyc+pi5rq2gkgejal36oRBnpKhSBk0TXsVbu34= ; Message-ID: <20060701214445.36616.qmail@web31805.mail.mud.yahoo.com> Received: from [24.54.196.198] by web31805.mail.mud.yahoo.com via HTTP; Sat, 01 Jul 2006 14:44:45 PDT Date: Sat, 1 Jul 2006 14:44:45 -0700 (PDT) From: Richard Broersma Jr Subject: Re: Left join? To: carlosreimer@terra.com.br, pgsql-sql@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/11 X-Sequence-Number: 25585 > In the following table, codsol, codate and codfec are foreign keys > referencing table func and I need some help to codify a SELECT command that > produces the following result set but instead of codsol, codate and codfec I > need the respectives names (column nome from table func). > > postgres=# select * from reqtran; > codreq | codsol | codate | codfec > --------+--------+--------+-------- > 1 | | | > 2 | 1 | | > 3 | 1 | 1 | > 4 | 1 | 1 | 1 > postgres=# \d func > Table "public.func" > Column | Type | Modifiers > --------+---------+----------- > codfun | integer | not null > nome | text | > Indexes: > "reqtran_codate_fkey" FOREIGN KEY (codate) REFERENCES func(codfun) > "reqtran_codfec_fkey" FOREIGN KEY (codfec) REFERENCES func(codfun) > "reqtran_codsol_fkey" FOREIGN KEY (codsol) REFERENCES func(codfun) Would this do what you need? select R1.codreq, CS.nome, CD.nome, CF.nome from rectran as R1 left join func as CS on (R1.codsol=CS.codefun) left join func as CD on (R1.codate=CD.codefun) left join func as CF on (R1.codfec=CF.codefun) ; Regards, Richard Broersma Jr.