Re: CONNECT BY - how to get leaves only

From: L. Scott Johnson <sjohnson_at_math.scarolina.edu>
Date: 19 Dec 1994 15:08:33 GMT
Message-ID: <3d47lh$4b6_at_redwood.cs.scarolina.edu>


kimmng_at_pebbles.uswnvg.com (Kim Ng) writes:

>Hi everyone,
 

>Mr. Chip Dawes suggested a very simple and elegant method of getting the
>"leaves" of the tree without even using "CONNECT BY". I am posting his
>solution in case somebody else is interested. (Read after "====" line)
 

>Thank you very much, Chip.
 

>===========================================================================
 

>From: chipd_at_mmsi.corp.mot.com (Chip Dawes)
>Apparently-To: kimmng_at_uswnvg.com
 

>The query I posted should still work. You would solve the same problem
>via a different technique. If your desired result is only the children
>and not the parents. You can find them 2 ways.
 

>Technique 1)
>Starting the root, decend each branch until you come to the terminating
>leaf, then print it.
> You choose correctly in trying to use the CONNECT BY statement to
>execute this alogithm.
 

>Technique 2)
>Find all the children who are not parents themselves.
>Avoid building the tree.

This works in most cases, assuming that you want the whole tree. If you are not starting at the root (parent is null, in Kim Ng's example), you need a start by clause, whcih forces the connect by clause. (Also, if the "tree" is broken odd things can occur). You must guarantee the integrity of the tree yourself to use minus (which typically isn't too much of a problem).

L.Scott Johnson Received on Mon Dec 19 1994 - 16:08:33 CET

Original text of this message