In MySQL the best (only?) solution I know of is to write a script (e.g. in
perl or python) that will traverse the tree for you.

e.g:

select a_keys from A
foreach key ( a_keys ){
  select c_keys from B
  ... etc.

  delete from b where key in ( a_keys )

If you were really looking for punishment you could create a table of
meta-data that descibed how the tables were related and then use that to do
the cascade delete.  And of course, LEFT JOIN is your friend for finding
reocrds in lower tables that do not have a matching reocrod in the parent
table, e.g.: SELECT b_keys FROM B LEFT JOIN A on ( common_key ) where
A.common_key IS NULL;.

--Bill


½ÉÃ溸 wrote:

> Hi.
> I came across serious problem.
> There is hierarchy among groups listed below like directory structure.
>
>      A(group)---------B(group)
>                      |
>                   -----C(group) --------D(group)
>                                           |
>                                ----E(group)
>                               |
>                                ----F(group)
>
> I want to delete A group. This requires deletion of all child groups.
> Above figure is a little simple but if this tree grows large that's my
> problem.
>
> Would you please tell me the answer?
>
> For reference table is like this.
>
> Field           Type
> groupname       varchar(50)
> groupno         int
> p_groupno       int             <- This means parent group no.
>
> Thanks in advance!!
>
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
>
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail <[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

--
Bill Adams
TriQuint Semiconductor




---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to