Re: how to do this join ?

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: <juerg(dot)rietmann(at)pup(dot)ch>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: how to do this join ?
Date: 2001-04-06 14:51:39
Message-ID: Pine.LNX.4.30.0104061646190.1603-100000@peter.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

juerg(dot)rietmann(at)pup(dot)ch writes:

> Hello there
>
> I have another SQL question. Please see the example :
>
> select *,
> (select a_typ from auftrag where a_nr=z_a_nr) as typ,
> (select a_t_definition_d from auftrags_typ where a_t_code=typ) as text
> from zylinder

select zylinder.*,
auftrag.a_typ
(select a_t_definition_d from auftrags_typ where a_t_code = auftrag.a_typ)
from zylinder, auftrag
where auftrag.a_nr = zylinder.z_a_nr;

or, using 7.1, maybe something like

select zylinder.*, auftrag.a_typ, auftrags_typ.a_t_definition
from (zylinder join auftrag on a_nr = z_a_nr)
left join auftrags_typ on a_t_code = a_typ

Other variations are possible, depending on the referential contraints you
have between the tables.

>
> I have three tables that I need data from. I'd like to use the <as typ> to
> temporary store the kind of auftrag and then use it to get the
> definition (clear text) from another table.
>
> The query returns that typ is not known .

--
Peter Eisentraut peter_e(at)gmx(dot)net http://yi.org/peter-e/

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Richard 2001-04-06 16:45:50 pg_dump and oid
Previous Message Tom Lane 2001-04-06 14:46:13 Re: how to do this join ?