Now there is a mysql table with a tree structure. The id field is a unique identification field. The value of pid field points to the id value of parent node. How to find all nested child nodes of an id node?

  mysql, question

The table has two fields, id and pid. pid points to the id of the parent node and the pid value of the following node is 0
How to query and find all child nodes of an id node?

There are many ways.
The first method:
Read out all the elements from the database at once.
select * from table_name
Then let the program use references to construct mostly arrays.
The second method:
Recursive to the database to query. Find out a part at a time.
The third method:
Use database tables to link queries. Constantly join with oneself to obtain data.
The fourth method:
Redesign your database. Change to another model.
GOOGLe yourself.

Before asking questions. GOOGLE the question first. There is an answer below. It is very detailed and exactly the same as the landlord’s question. . …