mySql copy rows into same table with key value changed (not overwriting existing)

INSERT INTO your_table (ID, ISO3, TEXT) 
SELECT ID, 'JPN', TEXT
FROM your_table 
WHERE ID IN ( list_of_ id's )

If you want to change a value in one cell, just hard-type the value instead of selecting from table (like I did with 'JPN').


If your key is auto_increment, and you have a table structure like primary_key | col1 | col2 | col3 then you can do something along the lines of

INSERT INTO table (
   col1, col2, col3
) SELECT col1, col2, col3
FROM table
WHERE primary_key IN(1, 2, 45, 54, 774, 4434 /* etc */);

Tags:

Mysql

Copy