recursion

From: Julien Cadiou <julienc(at)vicnet(dot)net(dot)au>
To: pgsql-sql(at)postgresql(dot)org
Subject: recursion
Date: 1999-11-25 01:15:54
Message-ID: 3.0.3.32.19991125121554.010b4d80@mail.vicnet.net.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi,

I'm trying to get my head around a simple problem but can't get it unless I expect too much of SQL/not enough of myself...

I'm building a links indexing application and want to maintain full relationality in the database. My categories table is as follows:

id|name |owner

--+--------------------+-----

1|Leisure | 0

2|Business | 0

5|Men's tennis lessons| 7

4|Finance | 2

10|Banks | 4

6|Stock Market | 4

8|Outdoors | 0

7|Men's Tennis | 3

9|Racket Sports | 3

3|Sports | 8

Each category has an id, a name and an owner. Subcategories are owned by other categories (the owner's id being the owner value) etc ... which is the relation between id and owner.

By knowing, for example, the primary key of Men's tennis lessons (5), I want to extract all categories in its path, all the way to the top, so as to get, in this case:

Outdoors > Sports > Men's Tennis > Men's Tennis Lessons

It seems to be a simple thing but after many joins and attempts at recursions, I still can't find it ...

I want to avoid multiple queries ...

Any ideas ? Thanks...

<bold>Julien CADIOU

</bold>Database Administrator

<bold>VICNET</bold> - Victoria's network

Phone: (03) 9669 9710

Fax: (03) 9669 9805

Web: http://www.vicnet.net.au/

Attachment Content-Type Size
unknown_filename text/enriched 1.4 KB

Browse pgsql-sql by date

  From Date Subject
Next Message Szucs Laszlo 1999-11-25 12:21:10 very slow connection
Previous Message Julien Cadiou 1999-11-25 01:09:48 recursive