I have 3 tables:
Words { wordId, name }
WordGroups { wordGroupId, type}
WordSets { wordSetId, wordId, wordGroupId}
I need to Insert new Word, and new WordGroup and after that insert WordSet with 2 new ids (wordId and WordGroupId).
I make this:
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);
It works, but I have doubts that this is the best way.
Does anyone have advice about better solution?