I am trying to set up a query which will select rows from a mysql db based on certain criteria. Once the rows are selected I need to then duplicate the row but with one value changed in the last column.
Can anyone tell me how I would go about doing this?
I can set up the select statement to choose the rows I need to based on certain criteria but I don';t know how to do the duplication part. Any help would be much appreciated.
Thanks in advance.
select one row to be duplicated, or duplicate all rows that are returned by the query?
you will have to give more information (table layout, example query, etc.) if you want anything more detailed
otherwise all i can tell you is that you would do the duplication part with an INSERT statement
To duplicate a row in mysql you can use this syntax:
INSERT INTO targetTable (field1, field2) (SELECT field1, field2 FROM sourceTable WHERE condition=check)
Try look on the net for "mysql duplicate and update row" .
i would not code the parentheses around the SELECT clause of the INSERT, but apparently in mysql it still works