I am writing mySQL query in PHP. I would like to duplicate a row in a table in a database. I would also like to add a timestamp as to when this duplication occurred using the NOW () function.
If I had a table called "people" with fields:
id, name, phone, dateCreated
and I wanted to duplicate this entry, I would do the following:
INSERT INTO people (id, name, phone, dateCreated)
SELECT id, name, phone, dateCreated
FROM people
WHERE id = '$id'
This will duplicate the record identified by the identifier $ id. I would like to make the same concept, but instead of copying dateCreated, I would like the query to insert the current datetime through the NOW () function, but I'm not sure how to structure this type of query.
Sort of:
INSERT INTO people (id, name, phone)
SELECT id, name, phone
FROM people
WHERE id = '$id'
(dateCreated) value (NOW())
How would I structure the query?
source
share