Můžete použít LAST_INSERT_ID () Vyzkoušejte toto:
INSERT INTO blahblah (test1, test2) VALUES ('test1', 'test2');
SELECT LAST_INSERT_ID() INTO @blahblah;
INSERT INTO blahblah2 (test1, test2) VALUES ('test1', 'test2');
INSERT INTO blahblah3 (test1, test2, lastid) VALUES ('test1', 'test2', @blahblah);