I have a table structure like this
mysql> SELECT id, name, parent_id FROM categories; +-------+------------+-----------+ | id | name | parent_id | +-------+------------+-----------+ | 15790 | Test | 0 | | 15791 | Test2 | 0 | | 16079 | Subtest | 15790 | | 16080 | Subtest 2 | 15790 | | 16081 | Subsubtest | 16079 | +-------+------------+-----------+
Now I want to find a parent for each child and sibling and return it in the correct order for removal.
So my conclusion in this case would be:
Array ( 16081, 16080, 16079, 15791, 15790 )
I cannot delete just by changing the parent identifiers, because this should be a solid backward move of the tree.
Also, I cannot / cannot change the structure of the table. Therefore, a building index type is needed.
source share