title: Submit multiple queries same time mysql inserting same id twice
body: <p>Want to submit auto-increment value of <code>table_a</code> into <code>table_b</code> at same time. I first inserting record  into <code>table_a</code> and then fetching last primary <code>id</code> from <code>table_a</code> and inserting it into <code>table_b</code>.
  It works well at slow speed like 20 records per sec, but a fast speed and multi user level it inserting duplicate id of <code>table_a</code> into <code>table_b</code>.</p>
  
  <p><a href="https://i.stack.imgur.com/gNxDf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gNxDf.png" alt="enter image description here"></a></p>
  
  <p>Is my approach is wrong ? Please suggest better way to do this.</p>
  
  <p>code</p>
  
  <pre><code>query1 = "insert into `table_a` (`aid`,`name`) values(null,'val')";
  
  query2 = "select `id` from `table_a` order by `id` desc limit 1";
  
  $aid='retrieved_value';
  
  query3 = "insert into table_b (`bid`,`aid`,`btype`) values (null,'$aid','val')";
  </code></pre>