SeanHarding Posted November 24, 2011 Share Posted November 24, 2011 INSERT INTO table1(id, chicken, beef, pork), table2(id, lettuce, cucumber) VALUES (NULL, '21', '22','23', NULL, '12', '13'); Is there a way to retrieve the AUTO INCREMENT of table1 id and insert it into table2 lettuce all within MySQL code? I can do this in PhP by mysql_insert_id(); but that would mean two MySQL queries. Sorry if my query is written incorrectly, was just a passing thought. Quote Link to comment Share on other sites More sharing options...
Andy-H Posted November 24, 2011 Share Posted November 24, 2011 MySQL's LAST_INSERT_ID() Quote Link to comment Share on other sites More sharing options...
SeanHarding Posted November 24, 2011 Author Share Posted November 24, 2011 MySQL's LAST_INSERT_ID() INSERT INTO table1(id, chicken, beef, pork), table2(id, chickenid, cucumber) VALUES (NULL, '21', '22', '23', NULL, LAST_INSERT_ID(), '13') ?? Quote Link to comment Share on other sites More sharing options...
fenway Posted November 25, 2011 Share Posted November 25, 2011 There's no such thing as a multi-table insert. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.