Re: Q: How do you do this in SQL ?

From: Peter Rak <po080016_at_pop.ke.sanet.sk>
Date: 1996/08/22
Message-ID: <321C86D0.49D1_at_pop.ke.sanet.sk>#1/1


Hi,

Read about CONNECT BY clause in SELECT statement.

                Good Luck, Peter.

Satish Katiyar wrote:
>
> I should know SQL better but for now can you please help me ?
>
> I have a table
>
> create table keywordclass (
> Id integer,
> KC char(1), // keyword or class ?
> Name char(15),
> Parent integer // refers to Id
> );
>
> It stores keyword hierarchies. Sample data is
>
> 1, 'C', 'Living', 1
> 2, 'C', 'Animal', 1
> 3, 'C', 'Plant', 1
> 4, 'K', 'Tiger', 2
> 5, 'C', 'Bird', 2
> 6, 'K', 'Parrot', 5
>
> How do you write a query in SQL that will retrieve the full
> keyword hierarchy (tree) ? (Assuming that names are unique).
> For example, retrieve the tree for "Animal", should return
>
> 2, 'C', 'Animal', 1
> 4, 'K', 'Tiger', 2
> 5, 'C', 'Bird', 2
> 6, 'K', 'Parrot', 5
>
> What will be the query if keywords and class names could be
> the same and duplicate ?
>
> Thanks a lot for your time. I would appreciate if you could
> send your reply as email.
>
> Satish
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> Satish Katiyar Email : katiyar_at_informix.com
> Informix Software, Inc. Work : (510) 873 - 8494
> 1111 Broadway, Suite 2000 Fax : (510) 873 - 6275
> Oakland, California 94607 Home : (510) 769 - 6953
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Received on Thu Aug 22 1996 - 00:00:00 CEST

Original text of this message