您可以将最后一个插入ID存储在变量中:
INSERT INTO table1 (title,userid) VALUES ('test', 1); SET @last_id_in_table1 = LAST_INSERT_ID();INSERT INTO table2 (parentid,otherid,userid) VALUES (@last_id_in_table1, 4, 1);或获取max id frm table1
INSERT INTO table1 (title,userid) VALUES ('test', 1); INSERT INTO table2 (parentid,otherid,userid) VALUES (LAST_INSERT_ID(), 4, 1); SELECt MAX(id) FROM table1;


