pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Abhinandan Raghavan <Abhinandan.Raghavan@unige.ch>
To: pgsql-sql@postgresql.org
Subject: Self-Join
Date: Tue, 06 Dec 2011 14:57:19 +0100
Message-ID: <4EDE1F3F.6060807@unige.ch> (raw)

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:


SELECTA.NAME <http://a.name/;,
              A.VALUE AS WEIGHT,
              B.VALUE AS HEIGHT,
              C.VALUE AS AGE

FROM NAV A,
            NAV B,
            NAV C

WHEREA.NAME <http://a.name/>=B.NAME <http://b.name/;
     ANDA.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

Attachments:

  [image/png] selfjoin_example.png (16.2K, ../4EDE1F3F.6060807@unige.ch/3-selfjoin_example.png)
  download | view image

view thread (15+ messages)  latest in thread

Message-ID: <4EDE1F3F.6060807@unige.ch>
Permalink:  ../4EDE1F3F.6060807@unige.ch/
Also on:    postgresql.org/message-id/4EDE1F3F.6060807@unige.ch

 · 

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: Abhinandan.Raghavan@unige.ch
  Subject: Re: Self-Join
  In-Reply-To: <4EDE1F3F.6060807@unige.ch>

* 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