pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gerard Samuel <gsam@trini0.org>
To: pgsql-php@postgresql.org
Subject: Self Join Help
Date: Sat, 19 Apr 2003 01:07:24 -0400
Message-ID: <3EA0D98C.8010004@trini0.org> (raw)

Im trying to figure out Self Joins with PostgreSQL.  The output of the 
second SQL is correct, because of the where a.id = b.pid,
but I would like to return all rows that are part of the tree.
i.e.
Foo
Apache
 - PHP
XHTML
News
 - World News
 - Tech News

Any help would be appreciated.
Thanks.

test=# select * from topics;
        id        |       pid        | topicname
------------------+------------------+------------
 AFAdDFoAPNX6wKbr | 0                | Foo
 AFAdDFoAPgTi9tAE | 0                | Apache
 AFAdDFoAPgTjCa4V | AFAdDFoAPgTi9tAE | PHP
 AFAdDFoAPlv1ENRn | 0                | XHTML
 AFAdDFoAPoSEWZaq | 0                | News
 AFAdDFoAPoSEaRPV | AFAdDFoAPoSEWZaq | World News
 AFAdDFoAPoSEee5_ | AFAdDFoAPoSEWZaq | Tech News
(7 rows)

test=# select a.topicname as parent, b.topicname as child from topics as 
a, topics as b where a.id = b.pid;
 parent |   child
--------+------------
 Apache | PHP
 News   | Tech News
 News   | World News
(3 rows)




view thread (5+ messages)  latest in thread

Message-ID: <3EA0D98C.8010004@trini0.org>
Permalink:  ../3EA0D98C.8010004@trini0.org/
Also on:    postgresql.org/message-id/3EA0D98C.8010004@trini0.org

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: gsam@trini0.org
  Subject: Re: Self Join Help
  In-Reply-To: <3EA0D98C.8010004@trini0.org>
  References: <3EA0D98C.8010004@trini0.org>

* 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