pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: gzscott2001@yahoo.ca
To: pgsql-sql@postgresql.org
Subject: Get A Tree from a table
Date: 5 Oct 2002 22:37:05 -0700
Message-ID: <341834e1.0210052137.7cbd6342@posting.google.com> (raw)

I like to do something like this:(build a tree from relationship)

 
 I have a table like this 

NODES__________________________________
 ParentID    Varchar(20)
 ParentType  varchar(20)
 ChildID     varchar(20)
 ChildType   varchar(20)

__________________________________
What in the table
 'A1', 'A', 'B1', 'B'
 'A2', 'A', 'B2', 'B'
 'A1', 'A', 'B3', 'B'
 'B1', 'B', 'C1', 'C'
 'B1', 'B', 'C2', 'C'
 'C1', 'C', 'D1', 'D'
 'A1', 'A', 'B4', 'B' 
 'B1', 'B', 'C5', 'C'

----------------------------------

now I like to get all nodes with 'A1' as root
to get the result like this
 'A1', 'A', 'B1', 'B'
 'B1', 'B', 'C1', 'C'
 'C1', 'C', 'D1', 'D'
 'B1', 'B', 'C2', 'C'
 'B1', 'B', 'C5', 'C'
 'A1', 'A', 'B3', 'B'
 'A1', 'A', 'B4', 'B' 

or I just like to get another tree start with 'B1'
like this
 'B1', 'B', 'C1', 'C'
 'C1', 'C', 'D1', 'D'
 'B1', 'B', 'C2', 'C'
 'B1', 'B', 'C5', 'C'


How can i make it by sql , and sql functions
Thanks lot and regards.

Scott



view thread (3+ messages)  latest in thread

Message-ID: <341834e1.0210052137.7cbd6342@posting.google.com>
Permalink:  ../341834e1.0210052137.7cbd6342@posting.google.com/
Also on:    postgresql.org/message-id/341834e1.0210052137.7cbd6342@posting.google.com

 · 

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: gzscott2001@yahoo.ca
  Subject: Re: Get A Tree from a table
  In-Reply-To: <341834e1.0210052137.7cbd6342@posting.google.com>

* 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