I found an example of the nested set model that I am trying to use on a project. I can’t understand just a small part of what is happening which in turn makes it so I can’t tweak it to my needs. The example looks like this:
LOCK TABLE nested_category WRITE;
SELECT @myRight := rgt FROM nested_category
WHERE name = 'TELEVISIONS';
UPDATE nested_category SET rgt = rgt + 2 WHERE rgt > @myRight;
UPDATE nested_category SET lft = lft + 2 WHERE lft > @myRight;
INSERT INTO nested_category(name, lft, rgt)
VALUES ('GAME CONSOLES', @myRight + 1, @myRight + 2);
UNLOCK TABLES;
I don’t understand what is going on in on the line SELECT @myRight:=rgt FROM nested_category.
More specifically, I am not grasping “@myRight := rgt”. What is going on there?
It looks like the code is assigning the value of
rgtfrom the row innested_categorywherename = 'TELEVISIONS'to the variable@myRight.