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.
For example:
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
Regards,
Neil Mansilla
whatUseek.com
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php