I'm designing a comments MySQL db, and my comments table has fields:
id
primary key, auto-incrthread
int, not nullcontent
All replies to the same comment, in addition to that root comment must share the same thread
. This is simple when a user is replying to a comment but what about when a new root comment is posted? I figured I would set thread=id
for root comments.
Problem is, I don't know how to write a query that will reuse the just created id
value within the same query when filling thread
. Is this even possible?
I've tried
INSERT INTO `comments`
VALUES (NULL, LAST_INSERT_ID(), 'hi there')
This gives me the id from the previous insert, not the current one. Do I have to use 2 queries?