MySQL Forums
Forum List  »  Newbie

Re: Select an array from one databank and compare it to one from another databank
Posted by: Barry Galbraith
Date: November 27, 2015 10:51PM

Frank, for step 2. you use LAST_INSERT_ID() to retrieve the id of the row you just inserted.

You can use it directly in the INSERT on the requests_subjects table

INSERT into requests(name,street, phone) VALUES ('name', 'street', 'phone');
INSERT into requests_subject(request_id, subject_id) VALUES (LAST_INSERT_ID(), 'subject_id');

LAST_INSERT_ID() is per connection, so if you have two (or more) connections at the same time, my LAST_INSERT_ID() is different from your LAST_INSERT_ID().

Good luck,
Barry.

Options: ReplyQuote




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.