Unlimited door-to-door deletion operations

Source: Internet
Author: User
The delete operation of an unlimited category uses an infinite category table associated with the parent ID. if you want to delete a temporary table, how can you delete all its descendants? Previously, the moderator wrote & nbsp; that is, there is no need to recursively construct a tree array, so here we can see whether there is a non-recursive method to find out all descendant elements that can be used to delete infinite categories of delete operations.
If you want to delete an infinite classification table associated with a parent ID, how can you delete all its descendants?
Previously, the moderator wrote that tree arrays are not recursively constructed, so here we can see whether there are any recursive methods that can be used to find all descendant elements that can be used to delete unlimited categories. share:
------ Solution --------------------
If you don't need recursion, I won't solve this problem. I hope the experts below will give answers.
In particular, I would like to ask a question: "Is there such a requirement in actual applications? The project manager won't let you use recursion ?"
Self-seeking troubles that do not aim to solve the problem are all hooligans... Haha...

------ Solution --------------------
Find orphan
SELECT id FROM table where pid not in (select id from table)
And then delete the corresponding record

It needs to be carried out in a loop, because each deletion may result in a new orphan.

Roughly like this:

Do {
$ Rs = mysql_query ('select group_concat (id) FROM table where pid not in (SELECT id from table )');
List ($ g) = mysql_fetch_row ($ rs );
Mysql_query ("delete from table where id in (g )");
} Where (mysql_affected_rows ());

------ Solution --------------------
The left and right values + the upper and lower values do not need recursion. the son finds the father and the upper and lower values. The ancestor finds the lower left and right values.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.