Search code examples
mysqlsqldatabasecopy-paste

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

Solution

  • 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