how to copy columns from one table to another in sql code example

Example 1: copy all values of a column to another column in sql in same table

UPDATE table SET columnB = columnA;

Example 2: sql update multiple columns from another table

-- Oracle
UPDATE table2 t2 SET (VALUE1, VALUE2) = 
    (SELECT COL1 AS VALUE1, COL1 AS VALUE2 FROM table1 t1 WHERE t1.ID = t2.ID);
-- SQL Server
UPDATE table2 t2 SET
    t2.VALUE1 = t1.COL1,
    t2.VALUE2 = t1.COL2
FROM table1 t1
INNER JOIN t2 ON t1.ID = t2.ID;
-- MySQL
UPDATE table2 t2 INNER JOIN table1 t1 USING (ID)
SET T2.VALUE1 = t1.COL1, t2.VALUE2 = t1.COL2;

Tags:

Sql Example