You don’t need to use another table as a related table. Isn’t your pid related to the parent id? If you want to make a related table, you can delete the pid, and then record the relationship in the related table.
As mentioned above, pid is the id of the parent address. Users should provide address hierarchical choices when adding, such as the first-level country. After selecting China, the second-level selection province, such as Guangdong Province, The third level selects cities and counties. If there is no Zhongshan City at this time and the user wants to add it, you already know that it is added to Guangdong Province when adding it. Then you should know the ID of the parent address of Zhongshan City and Guangdong Province. Directly Just insert the data and that’s it
insert into table(id,pid,name) select max(id),广东省id,'中山市' from table
You don’t need to use another table as a related table. Isn’t your pid related to the parent id?
If you want to make a related table, you can delete the pid, and then record the relationship in the related table.
As mentioned above, pid is the id of the parent address. Users should provide address hierarchical choices when adding, such as the first-level country. After selecting China, the second-level selection province, such as Guangdong Province, The third level selects cities and counties. If there is no Zhongshan City at this time and the user wants to add it, you already know that it is added to Guangdong Province when adding it. Then you should know the ID of the parent address of Zhongshan City and Guangdong Province. Directly Just insert the data and that’s it