From: Dan Nelson
Date: September 19 2002 5:59pm
Subject: Re: Auto Increment ID of Inserted Row
List-Archive: http://lists.mysql.com/mysql/120073
Message-Id: <20020919175903.GJ7768@dan.emsphone.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
In the last episode (Sep 19), Steven Kreuzer said:
> >What is the SQL to get the created AutoInc ID from a row that I have
> >just inserted?
>
> SELECT MAX(id_field) FROM table
Nope. If someone else inserted a record between the time you inserted
yours and the time you run that select, your answer will be wrong.
Use LAST_INSERT_ID(), or whatever construct your language provides for
retrieving it without doing another query.
--
Dan Nelson
dnelson@stripped