title: MySQL Bulk Insert Dependent on Another Table
body: <p>I have a case where I'm doing two queries: <code>query1</code> is a bulk <code>INSERT ... ON DUPLICATE KEY UPDATE</code> on <code>table1</code>. For <code>query2</code>, I want to do another bulk <code>INSERT</code> on <code>table2</code> with some application data along with using the ids inserted/updated from <code>query1</code>. I know I can do this with an intermediate query, selecting the ids I need from <code>table1</code> and then inserting them into <code>table2</code> along with application data, but I really want to avoid the extra network back-and-forth of that query along with the db overhead. Is there any way I can either get the ids inserted/updated from <code>query1</code> when running that, or do some kind of complex, but relatively less expensive <code>INSERT ... SELECT FROM</code> in <code>query2</code> to avoid this? </p>
  
  <p>As far as I know, getting ids added/modified returned from <code>query1</code> is impossible without a separate query, and I can't think of a way to batch <code>INSERT ... SELECT FROM</code> where the insertion values for each row are dependent on the selected value, but I'd love to be proven wrong, or shown a way around either of those.</p>