I have a table that contains many rows, ordered by the field 'seq'. I have selected rows 6-9 and I want to copy and paste them on row 3 for example. For that I'd like to create an SQL query that does the following:
INSERT INTO my_table ( seq, field1, field2.... )
SELECT seq, field1,field2..
FROM my_table
WHERE id IN ( 234, 233,232 )
(id field is the auto increment field that identifies my selected rows).
Now - I managed to duplicate the rows into the table. What is missing is to correctly update the 'seq' field in the following manner :
- In the pasted location (3) my rows should contain the values 3,4,5.
- All the original rows in that location should be incremented by 3 so that the original row (seq=3) should now become (seq=6) and all rows move 3 rows down the table.
Can this be achieved with an SQL query ?