List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:April 19 2002 8:31pm
Subject:Re: Selecting Information Just Inserted
View as plain text  
At 14:10 -0400 4/19/02, Andrew Kuebler wrote:
>Maybe someone can help me here..
>I'm inserting data with an AUTO_INCREMENT column and immediately after I
>need to use that new number for a corresponding record in another table.
>How am I able to extract that new number quickly? I could run a SELECT
>query after the INSERT using the MAX command, but if at a busy time
>another record is entered while the first record was being entered, it's
>possibly I may get the wrong number. If there a way to use the INSERT
>command and extract the new AUTO_INCREMENT all in one command?
>Any help is appreciated.

INSERT INTO tbl2 (id, ...) VALUES(LAST_INSERT_ID(), ...);

Selecting Information Just InsertedAndrew Kuebler19 Apr
  • Re: Selecting Information Just InsertedLuciano Barcaro19 Apr
  • Re: Selecting Information Just InsertedErik Price19 Apr
  • Re: Selecting Information Just InsertedPaul DuBois19 Apr
RE: Selecting Information Just InsertedScott L Hathaway22 Apr