Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8804589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:38:44+00:00 2026-06-14T01:38:44+00:00

In a slide http://www.slideshare.net/billkarwin/models-for-hierarchical-data , i saw a sql code (page 22): INSERT INTO

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T01:38:45+00:00Added an answer on June 14, 2026 at 1:38 am

    Yes, a single insert would be better than an insert followed by an update, but in this case the auto-generated id(?) is being used as a column value as well. The LAST_INSERT_ID() used in the path would not be the id of the current insert statement being performed, but that of the last (previous) insert.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I came across this slide: http://www.slideshare.net/stoyan/javascript-patterns#postComment at page 35: Option 5 + super +
I was going through Nicholas Zakas presentation on JavaScript here : http://www.slideshare.net/nzakas/writing-efficient-javascript (slide number:
On http://www.slideshare.net/eljefe/automated-deployment-with-phing in slide 15 they are talking about locking the live site when
I am following the symfony2 tutorial http://www.slideshare.net/weaverryan/symfony2-get-your-project-started . On slide 22 i must perform
here is the test page http://www.studioteknik.com/html/test-portfolio.html I got no error, but no hover-slide effect...
There is an image slider at the top of this page: http://www.example.com/ Each slide
I need Slide show like in the below site home page slide show, http://www.meshnetworks.ca/
I was looking at this Slideshow http://www.slideshare.net/CharJTF/structures-semantics-controls-and-more-html-5-is-here-3523971 and on slide #14 there are 3
I am using some excellent code for a photo slide show from http://www.queness.com/post/1450/jquery-photo-slide-show-with-slick-caption-tutorial-revisited .
Example website is http://www.wikihow.com/Main-Page , check the Recent Changes heading on the right side.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.