MySQL query to copy data from one column to another column

MySQL query to copy data from one column to another column

In this post i will tell you how to copy data from one column to another column in same table.

There is simple query to update record from one to another column in MySql.

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

There will be one question in your mind, is it possible in mysql ?. Yes it is possible in mysql.

Lets assume i have a table post with column id, column1, column2 and i want to copy value of column 1 into column2.

myql table structure for empty column2

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

UPDATE `post` SET `column2`=`column1`

Now you will get following output after running this query :

myql copy data from one column to another column

Now value of both column will be same.

Copy values from one column to another except some values within table:

If you want to copy some value of one column into another column within a table then run following queries :

UPDATE `post` SET `column2`=`column1` where `id`!=1

Now your output is like this :

myql Copy values from one column to another except some values

Phone: (+91) 8800417876
Noida, 201301