title: MySQL two LAST_INSERT_ID in one query
body: <p>I have 3 tables:</p>
  
  <pre><code>Words { wordId, name }
  WordGroups { wordGroupId, type}
  WordSets { wordSetId, wordId, wordGroupId}
  </code></pre>
  
  <p>I need to Insert new <code>Word</code>, and new <code>WordGroup</code> and after that insert <code>WordSet</code> with 2 new ids (wordId and WordGroupId).</p>
  
  <p>I make this:</p>
  
  <pre><code>INSERT INTO `wordgroups`(`type`) VALUES ('some_type'); 
  SET @gid:=LAST_INSERT_ID();
  INSERT INTO `words`(`name`) VALUES ('test name');
  SET @wid:=LAST_INSERT_ID();
  INSERT INTO `wordsets`(`wordGroupId`,`wordId`) VALUES(@gid,@wid);
  </code></pre>
  
  <p>It works, but I have doubts that this is the best way. </p>
  
  <p>Does anyone have advice about better solution?</p>