How do I duplicate a row?
I would like to duplicate a row and change one of the cells.
Is there a way to do it using a MySQL query? I know I can do it using a Select and Insert, but I wanted to know if there was a way to do it with one.
Assuming PHP as the application code, $id is the primary key (auto-incremented INT) of the row you want to duplicate and $newValue the different value for the "foo" column:
$sql = sprintf(
"INSERT INTO some_table (foo, bar) (SELECT '%s', bar FROM some_table WHERE id = %d)",
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)