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:
> SELECT LAST_INSERT_ID();
>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.
> Table schema:
> id INT UNSIGNED NOT NULL AUTO_INCREMENT,
> 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