pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Carlos H. Reimer <carlosreimer@terra.com.br>
To: pgsql-sql@postgresql.org
Subject: Left join?
Date: Sat, 1 Jul 2006 18:21:34 -0300
Message-ID: <PEEPKDFEHHEMKBBFPOOKKEFCDCAA.carlosreimer@terra.com.br> (raw)

Hi,

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
(4 rows)

Thanks in advance,

Carlos

__________________________________________________
Table definitions:

postgres=# \d func
     Table "public.func"
 Column |  Type   | Modifiers
--------+---------+-----------
 codfun | integer | not null
 nome   | text    |
Indexes:
    "func_pkey" PRIMARY KEY, btree (codfun)

postgres=# \d reqtran
    Table "public.reqtran"
 Column |  Type   | Modifiers
--------+---------+-----------
 codreq | integer | not null
 codsol | integer |
 codate | integer |
 codfec | integer |
Indexes:
    "reqtran_pkey" PRIMARY KEY, btree (codreq)
Foreign-key constraints:
    "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)
__________________________________________________
Table contents:

postgres=# select * from func;
 codfun | nome
--------+-------
      1 | nome1
      2 | nome2
      3 | nome3
(3 rows)

postgres=# select * from reqtran;
 codreq | codsol | codate | codfec
--------+--------+--------+--------
      1 |        |        |
      2 |      1 |        |
      3 |      1 |      1 |
      4 |      1 |      1 |      1
(4 rows)




view thread (13+ messages)  latest in thread

Message-ID: <PEEPKDFEHHEMKBBFPOOKKEFCDCAA.carlosreimer@terra.com.br>
Permalink:  ../PEEPKDFEHHEMKBBFPOOKKEFCDCAA.carlosreimer@terra.com.br/
Also on:    postgresql.org/message-id/PEEPKDFEHHEMKBBFPOOKKEFCDCAA.carlosreimer@terra.com.br

 · 

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: carlosreimer@terra.com.br
  Subject: Re: Left join?
  In-Reply-To: <PEEPKDFEHHEMKBBFPOOKKEFCDCAA.carlosreimer@terra.com.br>

* 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