 <p>There is no way to get a set of IDs as a result of a bulk <code>INSERT</code>. </p> <p>One option you have is indeed to run a <code>SELECT</code> query to get the IDs and use them in the second bulk <code>INSERT</code>. But that's a hassle.</p> <p>Another option is to run the 2nd bulk <code>INSERT</code> into a <em>temporary</em> table, let's call it <code>table3</code>, then use <code>INSERT INTO table2 ... SELECT FROM ... table1 JOIN table3 ...</code></p> <p>With a similar use case we eventually found that this is the fastest option, given that you index <code>table3</code> correctly. Note that in this case you don't have a <code>SELECT</code> that you need to loop over in your code, which is nice.</p>