Skip site navigation (1) Skip section navigation (2)

Prent-Child relationships in SQL

From: "Gibson Chimhamhiwa" <gchimhamhiwa(at)gmail(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Subject: Prent-Child relationships in SQL
Date: 2008-07-25 11:42:38
Message-ID: f2b0d8200807250442j480e6021l53267e90280e5bc0@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-admin
Hi All,

I have a simple table below and I want to be able to write a SQL select
query that returns the grouping_ids until I get no more children. The
parent_grouping_id column is the parent to the grouping_id child column. Can
somebody please advise me how I can do this in postgreSQL.

CREATE TABLE grouping
(
  grouping_id int4 NOT NULL,
  version int4,
  parent_grouping_id int4,
  topic_topic_id int4,
  CONSTRAINT grouping_pkey PRIMARY KEY (grouping_id),
  CONSTRAINT fk1e2e9d036852722d FOREIGN KEY (topic_topic_id)
      REFERENCES topic (topic_id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT fk1e2e9d03a1bfbfe FOREIGN KEY (topic_topic_id)
      REFERENCES topic (topic_id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT fk1e2e9d03cdaf7222 FOREIGN KEY (parent_grouping_id)
      REFERENCES grouping (grouping_id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITHOUT OIDS;
ALTER TABLE grouping OWNER TO napdba;

Thanks In Advance.

Responses

pgsql-admin by date

Next:From: Tino SchwarzeDate: 2008-07-25 11:47:28
Subject: Re: How to recover deleted data........
Previous:From: neo3 matrixDate: 2008-07-25 11:19:48
Subject: How to recover deleted data........

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group