I have one table (in phpmyadmin) with the following fields and structure:
Table 1 id | sponsor 1 | -1 2 | 1 3 | 1 4 | 2 5 | 4 6 | 4
Now I want to insert the data from the table above into a new table, as shown below:
Table 2 id | children 1 | 2,3 2 | 4 3 | 4 | 5,6 5 | 6 |
This is actually a Tree structure that I saved in the mysql database.
I already wrote a script in php, but since table 1 has more than 100K lines, so it takes too much time. Please tell me an efficient SQL query to quickly complete this task.
source share