In a slide http://www.slideshare.net/billkarwin/models-for-hierarchical-data, i saw a sql code (page 22):
INSERT INTO Comments (author, comment)
VALUES (‘Ollie’, ‘Good job!’);
SELECT path FROM Comments
WHERE comment_id = 7;
UPDATE Comments
SET path = $parent_path || LAST_INSERT_ID() || ‘/’
WHERE comment_id = LAST_INSERT_ID();
I think we can optimize it:
SELECT path FROM Comments
WHERE comment_id = 7;
INSERT INTO Comments (author, comment, path )
VALUES (‘Ollie’, ‘Good job!’, $parent_path || LAST_INSERT_ID() || ‘/’);
Am I right?