Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Nested Set Model Deleting subtrees Trees In The Database - Advanced data structures

193,136 views

Published on

Nested Set Model
Deleting subtrees
DELETE FROM orgchart
WHERE lft BETWEEN (SELECT lft
FROM orgchart
WHERE emp = :start_node)
AND (SELECT rgt
FROM orgchart
Filling gaps WHERE emp = :start_node);
CREATE VIEW LftRgt (seq) AS
SELECT lft FROM orgchart
UNION ALL
SELECT rgt FROM orgchart;

UPDATE orgchart SET
lft = (SELECT COUNT(*) FROM LftRgt WHERE seq <= lft),
rgt = (SELECT COUNT(*) FROM LftRgt WHERE seq <= rgt)

29

Published in: Technology, Business
  • Hello! Get Your Professional Job-Winning Resume Here - Check our website! https://vk.cc/818RFv
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Thank you for this
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Hi Lorenzo, could you take a look of this link in which I design some new solutions: https://github.com/drinkjava2/Multiple-Columns-Tree , with 2 fields (sorted) "line" and "level" and a end tag, will easy do query/add/delete operation.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • please make this downloadable
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • nice but why i cannot save it ?it's worthless then..
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

×