MySQL Forums
Forum List  »  General

[newbie] Get ID from previous INSERT?
Posted by: John Doe
Date: February 15, 2023 07:42AM

Hello,

This is a newbie SQL question.

I need to add a new record into two tables, where the second table requires the ID set in the first time.

Is there a SELECT I could use to get it?

Pseudo-code:
==============
INSERT INTO table1 (somecol) VALUES ('blah');
??? SELECT set ID=LASTROWID(table1);
INSERT INTO table2 (table1_id,someothercol) VALUES (ID,'blah2');
==============

If need be, I can turn off the Php application that uses MySQL so that no user makes changes to it.

Thank you.

Options: ReplyQuote


Subject
Written By
Posted
[newbie] Get ID from previous INSERT?
February 15, 2023 07:42AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.