Re: Left join?

From: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>
To: carlosreimer(at)terra(dot)com(dot)br, pgsql-sql(at)postgresql(dot)org
Subject: Re: Left join?
Date: 2006-07-01 21:44:45
Message-ID: 20060701214445.36616.qmail@web31805.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

  • Left join? at 2006-07-01 21:21:34 from Carlos H. Reimer

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Carlos H. Reimer 2006-07-02 12:52:35 RES: Left join?
Previous Message Carlos H. Reimer 2006-07-01 21:21:34 Left join?