title: mysql - call to insert into another table on every value of select
body: <p>I'm currently migrating data from our old database schema into a new one.</p>
  
  <p>I have a table called <code>Product</code> on my old database, on my new database schema I still have a <code>Product</code> table and a new column for <code>b_id</code>, and another table <code>B</code>.</p>
  
  <p>During migration, I will need to insert an entry to table <code>B</code> for every product that I have in my table and update the <code>Product</code> table to set the <code>b_id</code> for the newly created entry on b for this product. How can I accomplish this?</p>
  
  <p>To transfer the data for the product table, I have:</p>
  
  <pre><code>INSERT INTO newSchema.Product
  SELECT id, prodName 
  FROM oldSchema.Product
  </code></pre>
  
  <p>I'm thinking of looping into the <code>oldSchema.Product</code> and for every product, have a call to <code>INSERT INTO B</code> and <code>UPDATE TABLE Product</code>, but no idea how to put this into code.</p>
  
  <p>Any help will be appreciated. Thanks!</p>