Re: Self-Join

From: Bèrto ëd Sèra <berto(dot)d(dot)sera(at)gmail(dot)com>
To: Abhinandan Raghavan <Abhinandan(dot)Raghavan(at)unige(dot)ch>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Self-Join
Date: 2011-12-06 14:04:14
Message-ID: CAKwGa__sNtwZaRdOfyNfsBUWs4gBC2yO1=d3mZ_9w2ELmfqOeQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi Abhinandan,

it's just the same outer join you'd do in Oracle, see:

http://www.postgresql.org/docs/9.1/static/tutorial-join.html

Bèrto

On 6 December 2011 16:57, Abhinandan Raghavan
<Abhinandan(dot)Raghavan(at)unige(dot)ch>wrote:

> Hi,
>
> I'm looking to frame an SQL statement in Postgres for what's explained in
> the attached image.
>
> The original table is at the top and is called NAV (Short for Name,
> Attribute, Value). I want to create a view (NWHA_View) involving values
> from within (presumably from a self join). I would've normally created a
> view in the following way:
>
>
> SELECT A.NAME <http://a.name/>,
> A.VALUE AS WEIGHT,
> B.VALUE AS HEIGHT,
> C.VALUE AS AGE
>
> FROM NAV A,
> NAV B,
> NAV C
>
> WHERE A.NAME <http://a.name/> = B.NAME <http://b.name/>
> AND A.NAME <http://a.name/> = C.NAME <http://c.name/>
> AND A.ATTRIBUTE = 'Weight'
> AND B.ATTRIBUTE = 'Height'
> AND C.ATTRIBUTE = 'Age'
>
>
> The only problem when I create a view with the above select statement is
> that when there are no entries for the field name "AGE" (in the case of
> David), then the row does not get displayed. What's the way out in
> Postgresql? I know the way it is addressed in Oracle but it doesn't seem to
> work in Postgresql.
>
> Thanks.
>
> Abhi
>
>
>
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>
>

--
==============================
If Pac-Man had affected us as kids, we'd all be running around in a
darkened room munching pills and listening to repetitive music.

In response to

  • Self-Join at 2011-12-06 13:57:19 from Abhinandan Raghavan

Browse pgsql-sql by date

  From Date Subject
Next Message Oliveiros d'Azevedo Cristina 2011-12-06 14:39:47 Re: Self-Join
Previous Message Abhinandan Raghavan 2011-12-06 13:57:19 Self-Join