I\'d need a MySQL query that moves a node and all its children within a nested set. I found this site, but that function just seems so illogical - there\'s no universe
Moving subtrees around is very expensive and complex in the Nested Sets design.
You should consider a different design for representing trees.
For example, if you use the Path Enumeration design, you store the list of direct ancestors of each node as a concatenated string.
id path
1 1/
2 1/2/
3 1/3/
4 1/3/4/
5 1/3/5/
Then moving a subtree (say node 3 moves to be a child of node 2):
UPDATE Tree t
JOIN Tree node2 ON (node2.id = 2)
JOIN Tree node3 ON (node3.id = 3)
SET t.path = CONCAT(node2.path, REPLACE(t.path, node3.path, node2.path))
WHERE t.path LIKE CONCAT(node3.path, '%');