On Sat, Jan 31, 2004 at 08:31:38PM +0100, A.J.Millan wrote:
> LAST_INSERT_ID() function:
> 
> This other one has proven before, but in my case it returns many results (in
> fact, the last one es the desired data).
> 

It will return a single result if you just do this:

SELECT LAST_INSERT_ID();

Do *NOT* do this:

SELECT LAST_INSERT_ID() FROM mytable;

That would return the same value for each row of mytable, which is quite
useless. Note that LAST_INSERT_ID() is not kept per table, but just once
per connection, so 'mytable' is of no use here.


> "The most direct way is to SELECT the MAX() value from the table:"
> 
> OK You are right!!.   In my opinion it is not only the "most direct", but
> the ONLY direct .  I admit that I had not understood the meaning of  this
> sentence :-(
> 

Don't use this instead of LAST_INSERT_ID() because some other process
may have inserted another record in the mean time.


Regards,

Fred.


-- 
Fred van Engen                              XB Networks B.V.
email: [EMAIL PROTECTED]                Televisieweg 2
tel: +31 36 5462400                         1322 AC  Almere
fax: +31 36 5462424                         The Netherlands

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

Reply via email to