title: MYSQL Update all foreign key values
body: <p>I have two identical tables that are located in two identical databases(with different name). I want to merge these two tables, but their primary keys are used in other tables,   </p>
  
  <p>these tables look like this:</p>
  
  <p><strong>Table A</strong>  </p>
  
  <pre><code>id     column1     column2    column3
  ___    ________    _______    ________
   1        text        text      text
   2        text        text      text
   3        text        text      text   
  </code></pre>
  
  <p><strong>Table B</strong>  </p>
  
  <pre><code>id     column1     column2    column3
  ___    ________    _______    ________
   2        text        text      text
   3        text        text      text
   4        text        text      text 
  </code></pre>
  
  <p><strong>tables that are linked to Table A</strong>  </p>
  
  <p><strong>Link A</strong>  </p>
  
  <pre><code>id     column1     tableA_ID
  ___    ________    _______  
   1        text        2     
   2        text        3      
   3        text        4   
  </code></pre>
  
  <p><strong>Link B</strong>  </p>
  
  <pre><code>id     column1     tableA_ID
  ___    ________    _______  
   1        text        3     
   2        text        3      
   3        text        2    
  </code></pre>
  
  <p>Please note, the tables have identical <code>id</code>'s, this means when I do the merge, I have to change the <code>id</code>'s of the second table. Remember the <em>second table's primary keys are used in other tables.</em>   </p>
  
  <p>I wrote this query to merge the two tables:  </p>
  
  <pre><code>INSERT INTO db_A.`Table_A`(`column2`,`column3`) 
      SELECT `column2`,`column3` FROM db_B.`Table_B`; 
  </code></pre>
  
  <p>This query will correctly copy the records of the second table to the first table.  </p>
  
  <p>Now I want to also move the data of the tables that are linked with <code>Table B</code>, I can use the same query, but now the foreign key will not match, because the <code>ID</code> they were linked with has been changed.</p>
  
  <p>How do I update them so that the <code>ID</code> will match again?</p>
  
  <p><strong>NB: I do not have the ON UPDATE CASCADE constraint on those tables</strong></p>
  
  <p>I hope this make sense, I will try to improve this question so that everyone understands it.</p>
  
  <p><strong>Database Info</strong></p>
  
  <pre><code>Type  : MySQL
  Engine: MyISAM
  </code></pre>