MySQL: Duplicate a column/field

You may need to duplicate an existing column/field in a MySQL table with the exact same values in the new column/field as you have in the current or original column/field.

First, you’ll create a new column to the table as needed:

ALTER TABLE `tablename` ADD `column2` TEXT NOT NULL;

Then you’ll simply execute an UPDATE query to duplicate/copy the column over to the new column:

UPDATE `table` SET `column2` = `column1`;

And that’s it, you’ve duplicated your column/field in your MySQL table!

You can update a MySQL field/column values with the values of multiple other MySQL fields/columns as well. For example, say you have a ‘full_name’ table field which is empty and you want to set this ‘full_name’ field value for each record to it’s ‘first_name’ and ‘last_name’ fields concatenated to form a full name, you can use MySQL CONCAT() function.

UPDATE `table` SET `full_name` = CONCAT(`first_name`, ' ', `last_name`);

The second parameter in the CONCAT() function above is just to create a space between the first and last name.