Copy data from one column to another column on the same or another table

MySQL

SQL to copy data from one column to other column on the same table

UPDATE table
SET column1 = column2

SQL to copy data from one column to other column on another table

UPDATE table1
SET table1.column1 = table2.column2
FROM table1
JOIN table2
ON - join condition

If the column1 does not allow NULL, use ISNULL(). It will replace NULL with an empty string. Like this:

UPDATE table1
SET table1.column1 = ISNULL(table2.column2)
FROM table1
JOIN table2
ON - join condition

You need to specify the join condition to update the rows.

If the target table is empty, then you need to use an INSERT query:

INSERT INTO table1 (column1)
SELECT column2 FROM table2

Have something to Add?

Loading Facebook Comments ...
Loading Disqus Comments ...