Robert Crowell <[EMAIL PROTECTED]> wrote on 11/11/2005 12:39:37 AM:

> 
> Hello,
> 
> If I am relying on MySQL's AUTO_INCREMENT feature for the id for a 
table, how
> can I reliably retrieve the ID of an item I just entered into the 
database?
> 
> For instance, I have a table that stores first names, and has an id 
field that
> is generated via AUTO_INCREMENT.  However, this id will uniquely 
identify the
> first name we enter (say "James") for the rest of my application.  So, 
if I am
> adding entries to my table, I insert "James" and a unique id is 
> generated.  How
> do I get this id out of the table again?  If I, for instance, add 
> "James" again
> later and want to get the id of this new "James", how would I do it?
> 
> The problem is that there are many "James" entries in our database, but 
I need
> to get the unique of this "James" I just put in.  I can't search for 
"James"
> because there are lots of them in the table.
> 
> Any ideas?  Thanks a lot.
> 
> -Rob Crowell
> 

TFM is your friend. What you are looking for is LAST_INSERT_ID()

http://dev.mysql.com/doc/refman/4.1/en/information-functions.html

Shawn Green
Database Administrator
Unimin Corporation - Spruce Pine

Reply via email to