pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Broersma Jr <rabroersma@yahoo.com>
To: carlosreimer@terra.com.br
To: pgsql-sql@postgresql.org
Subject: Re: Left join?
Date: Sat, 1 Jul 2006 14:44:45 -0700 (PDT)
Message-ID: <20060701214445.36616.qmail@web31805.mail.mud.yahoo.com> (raw)
In-Reply-To: <PEEPKDFEHHEMKBBFPOOKKEFCDCAA.carlosreimer@terra.com.br>

> 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.



view thread (13+ messages)

Message-ID: <20060701214445.36616.qmail@web31805.mail.mud.yahoo.com>
Permalink:  ../20060701214445.36616.qmail@web31805.mail.mud.yahoo.com/
Also on:    postgresql.org/message-id/20060701214445.36616.qmail@web31805.mail.mud.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: rabroersma@yahoo.com, carlosreimer@terra.com.br
  Subject: Re: Left join?
  In-Reply-To: <20060701214445.36616.qmail@web31805.mail.mud.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox