MySQL Lists are EOL. Please join:

List:General Discussion« Previous MessageNext Message »
From:Neil Mansilla Date:September 18 2002 1:30pm
Subject:Re: How to use Auto Increment
View as plain text  
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.

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