MySQL: Update one Table Column with content from another Table Column

logo-mysql-110x57

In this example we have in Table_A information in Column migration_background which we want to have in Table_B in Column migration_background_custom, because something has changed in the Datamodel, because we use a flexible and configurable Application, which adds new Columns to customizable Modules..

UPDATE Table_A a, Table_B b
SET b.migration_background_custom = a.migration_background
SET a.migration_background = 'yes'
WHERE a.migration_background LIKE '%yes%' AND
a.client_id = b.client_id_cstm;

Now we have corrected our data and only if a customer has a Migration Background (migration_background = ‚yes‘), he’ll also has an entry in Table_B (migration_background_custom) with the value he had before in Table_A.