MySQL Lists are EOL. Please join:

List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:September 19 2002 1:21am
Subject:Re: How to use Auto Increment
View as plain text  
At 9:30 -0400 9/18/02, Neil Mansilla wrote:
>On Wed, 18 Sep 2002, Rajesh Kanade wrote:
>>  Hi All
>>  I am new to MY SQL .
>>  I am writing a script where I will have 2 insert statements
>>  The first insert is into a table which has an Auto_Increment field.
>>  I want to know the value which was inserted in this Auto_increment field and
>>  use it in the second INSERT statement.
>>  How can I do it in MySQL.
>Rajesh, if you wish to pull the value of the last AUTO_INCREMENT issued,
>use this query:
>The second INSERT statement really shouldn't need the value of the last
>AUTO_INCREMENT issued, since it should just get the next number in
>sequence, well, automatically.

That's assuming both INSERTs are into the same table.  I got the idea
that he wanted the AUTO_INCREMENT value for use in inserting a record
into a different but related table.

>For example:
>   Table schema:
>     name  VARCHAR(100) NOT NULL,
>     primary key (id)
>   INSERT INTO Table VALUES (null,'Neil');
>   INSERT INTO Table VALUES (null,'Rajesh');
>If these were the first two records, the two rows would look like this:
>1  |  Neil
>2  |  Rajesh
>Neil Mansilla

How to use Auto IncrementRajesh Kanade18 Sep
  • Re: How to use Auto IncrementDanny Haworth18 Sep
  • Re: How to use Auto IncrementNeil Mansilla18 Sep
Re: How to use Auto IncrementPaul DuBois19 Sep