MySQL Forums
Forum List  »  PHP

Re: Autonumber - how do i find out what has been entered
Posted by: Jonathan Stephens
Date: May 17, 2005 06:27PM

Use

SELECT LAST_INSERT_ID();

to get the most recent AUTO_INCREMENT value assigned during the current session regardless of which table the INSERT took place in (note that this changes as soon as you perform another INSERT, regardless of which table is involved)

or

SELECT MAX(id) FROM mytable;

to get the greatest id value in mytable whether or not it was set during the current session.

LAST_INSERT_ID() is probably a bit faster.

Note that these are MySQL functions, and not PHP functions.

You might find this helpful: http://dev.mysql.com/doc/mysql/en/getting-unique-id.html

Jon Stephens
MySQL Documentation Team @ Oracle

MySQL Dev Zone
MySQL Server Documentation
Oracle

Options: ReplyQuote


Subject
Written By
Posted
Re: Autonumber - how do i find out what has been entered
May 17, 2005 06:27PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.