Update ancestors in a nested set?

Posted by Travis on Stack Overflow See other posts from Stack Overflow or by Travis
Published on 2010-05-27T23:50:36Z Indexed on 2010/05/27 23:51 UTC
Read the original article Hit count: 192

Filed under:
|
|

I am using nested sets to represent a tree in mysql, like so:

Tree
ID
title
lft
rgt

Given the ID of a node in the tree, what is the easiest / best way to UPDATE that node as well as all of it's ancestors?

For example, let's say that the node ID (36) is 4 levels deep in the tree. I would like to update its title, as well as every parent node's title, all the way to the root, to the word "fish". (Should be four updates in all.)

Thanks for your help!

© Stack Overflow or respective owner

Related posts about mysql

Related posts about mysql-query