Copy data from one column to another column in MySQL



In this tutorial I will show you how to copy data from one column to another column in same table in MySQL. There is a simple query to update record from one to another column in MySql.

Most of the time we just need to copy a particular record from one table to another but sometime we need to copy the whole column values to another column in same table.

For example I have a table ‘data’ with column id, column1, column2 and I want to copy value of column 1 into column2.

Now we will use following query to copy the whole column value into another column:

UPDATE `data` SET `column2`=`column1`;

You will get following output after running above query:

Now if you want to copy some value of one column into another column within a table then run following query:

UPDATE `post` SET `column2`=`column1` where `id`!=2;