After doing an INSERT, you may do
SELECT last_insert_id();
and it will return the last id the last INSERT command used. it doesn't matter if your
MySQL server is very busy doing inserts, if
you call 'SELECT last_insert_id()' right after the INSERT, you will get the correct
value. last_insert_id() returns the last insert
ID of that connection ID, so you will get the correct values.
---------------------
Johnny Withers
[EMAIL PROTECTED]
p. 601.853.0211
c. 601.954.9133
-----Original Message-----
From: Josh Burroughs [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 06, 2001 6:18 PM
To: [EMAIL PROTECTED]
Subject: INSERT question...
Hi-o! I was wondering if it's possible when inserting a value into a table
that has an auto_increment field to have MySQL return the value of the
auto_increment field right after doing the insert, w/out having to run a
seperate query?
For example if I had a table with two collums, ID and name. Where ID is an
int field with auto_increment set, and is the primary key. and name is
just a varchar. and did this:
INSERT INTO some_table (name) VALUES("bob");
I'd like for the query to return the value for ID that was just assigned.
Is there a way to do this all in one SQL statement?
Thanks in advance!
"Listen: We are here on Earth to fart around. Don't let anybody tell you
any different!" - Kurt Vonnegut
Josh Burroughs
[EMAIL PROTECTED]
---------------------------------------------------------------------
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
---------------------------------------------------------------------
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