Mild Fuzz Mild Fuzz - 7 months ago 16
SQL Question

Copy one column from one database to another

I need to copy the content from a column in one database into the matching column in another, so that the same content goes in the record with the same ID. Something like the following pseudo stuff:

SET database2.table1.columnA TO database1.table1.columnA WHERE database2.id = database1.id

Answer

You can use JOIN in an UPDATE statement:

UPDATE table1 t1 
JOIN database1.table1 as t2 ON
   t1.id = t2.id
SET
   t1.columnA = t2.columnA
Comments