MySQL queries Summary & lt; unlimited categories, recursively retrieves or deletes all subclasses under the parent class & gt;

Source: Internet
Author: User

An infinite classification table. The primary table field FID and parent class ID field FPID are simple columns. Retrieve the dataset's SQL statement with a as (select FID from table where FID = 'value' union allselect x. FID from Table x, a where x. FPID =. FID) select * from a: the SQL statement www.2cto.com with a as (select FID from table where FID = 'value' union allselect x. FID from Table x, a where x. FPID =. FID) delete from table where FID in (select FID from)
1. x can be understood as a slave table name in a alias or join statement. if you rewrite the search statement with a as (select * from table where FID = 'value' union allselect. * from ArticleType x, a where x. FPID =. FID) select * from a may show that the "statement is terminated. The maximum recursion 100 error is returned before the statement is executed. The solution is as follows:

When the union clause retrieves data sets, the number/type of their fields must be the same/Corresponding. This is my understanding with a as (select Field 1, Field 2, Field 3, field 4 .. from table where FID = 'value' union allselect x. field 1, x. field 2, x. field 3, x. field 4 .. from table x, a where x. FPID =. FID) select * from a www.2cto.com PS, but someone else can give you two points... ". I know that everyone's experience and technical skills are different. Although cainiao like me have less than a year of graduation work, there are still many shortcomings and areas to learn, but they are not very lucky, if you encounter problems in your work practice at ordinary times, you have the opportunity and time to write your thoughts and accumulate a little bit. Author wisonlee

Related Article

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.