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. Link to comment https://forums.phpfreaks.com/topic/251729-get-auto-increment-and-store-into-a-separate-table/ Share on other sites More sharing options...
Andy-H Posted November 24, 2011 Share Posted November 24, 2011 MySQL's LAST_INSERT_ID() Link to comment https://forums.phpfreaks.com/topic/251729-get-auto-increment-and-store-into-a-separate-table/#findComment-1290951 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') ?? Link to comment https://forums.phpfreaks.com/topic/251729-get-auto-increment-and-store-into-a-separate-table/#findComment-1290953 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. Link to comment https://forums.phpfreaks.com/topic/251729-get-auto-increment-and-store-into-a-separate-table/#findComment-1291112 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.