Duplicate row in mySQL

admin

Administrator
Staff member
Hi there, I was just wondering if there is a quick, easy way to this.

I have a table of messages, I want to be able to duplicate a message, changing only 1 field. The messages table also holds a reply value and all messages that are a reply to the initial message need to have 1 field changed too.

My "Move" command is like so:
UPDATE messages SET board='$moveto' WHERE id='$id' OR replyto='$id'
I want the same effect but create copies instead of changing the initial values.

Is there way to do this easily withou doing:
- SELECT old message
- INSERT new message with changes
- SELECT new message to get "id"
- Loop through replies to old message
--- SELECT reply to old message
--- INSERT reply to new message

I thought about using INSERT SELECT but that doesn't allow you to use the same table in the INSERT & SELCT part of the statement.
 
Back
Top