title: Insert from MySQL joined table
body: <p>I have two databases named <code>drupal</code> and <code>wordpress</code>. I try to migrate post image paths from drupal 6 to wp.</p>
  
  <p>Tables <code>drupal.content_field_image</code> and <code>drupal_files</code> contain necessary data:</p>
  
  <p><code>drupal.content_field_image</code> has field_image_fid - nid pair. <code>drupal.drupal_files</code> has fid - filepath pair (field_image_fid = fid). </p>
  
  <p>I need to get the table that contains both nid and filepath, so I join this tables:</p>
  
  <pre><code>SELECT * 
  FROM `content_field_image` 
  JOIN `files` ON content_field_image.field_image_fid = files.fid;
  </code></pre>
  
  <p>Now I need to insert data to <code>wordpress</code> db so that:</p>
  
  <p><code>meta_id</code> = 34 + n (n is increment)</p>
  
  <p><code>post_id</code> = <code>nid</code> from joined table</p>
  
  <p><code>meta_key</code> = fifu_image_url</p>
  
  <p><code>meta_value</code> = <code>filepath</code> from joined table</p>
  
  <p>So I have some questions:</p>
  
  <ol>
  <li>How to make insert from joined table?</li>
  <li>How to make while-like loop to insert every entry from joined table?</li>
  <li>How to make n increment by 1 after every insert?</li>
  </ol>