Hi Robert,

You can use the function LAST_INSERT_ID() after the insert, this will
return the id that was just assigned.

It is documented here :

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

Regards

David Logan
Database Administrator
HP Managed Services
148 Frome Street,
Adelaide 5000
Australia

+61 8 8408 4273 - Work
+61 417 268 665 - Mobile
+61 8 8408 4259 - Fax


-----Original Message-----
From: Robert Crowell [mailto:[EMAIL PROTECTED] 
Sent: Friday, 11 November 2005 4:10 PM
To: mysql@lists.mysql.com
Subject: Database IDs


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

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to