recursion

Поиск
Список
Период
Сортировка
От Julien Cadiou
Тема recursion
Дата
Msg-id 3.0.3.32.19991125121554.010b4d80@mail.vicnet.net.au
обсуждение исходный текст
Список 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
isas 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
ownervalue) 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
theway 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/




В списке pgsql-sql по дате отправления:

Предыдущее
От: Julien Cadiou
Дата:
Сообщение: recursive
Следующее
От: Szucs Laszlo
Дата:
Сообщение: very slow connection