sketchgal — 2011-08-30T05:40:42-04:00 — #1
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.
r937 — 2011-08-30T08:18:54-04:00 — #2
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
marplo — 2011-08-30T12:10:58-04:00 — #3
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" .
r937 — 2011-08-30T13:06:40-04:00 — #4
i would not code the parentheses around the SELECT clause of the INSERT, but apparently in mysql it still works