List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:May 30 1999 1:19am
Subject:Re: last_insert_id() - strange ??
View as plain text  
At 5:49 PM -0700 5/29/1999, Darren Sweeney wrote:
>Thanks .. the only problem is I have 8 tables in the dB .. how will it know
>which one to look at?

It won't.  last_insert_id() is connection-specific, not table-specific.
You have to keep track of the table yourself.  Is there some reason that
makes that difficult?  I would think you could just fetch last_insert_id()
when you insert into one of these tables, and put the value in a hash indexed
on table name.  Or something.


>
>I need to be able to call this in Perl and then use something like $lastid =
>$sth->fetchrow; to get the value... this would be OK now as all the rows are
>the same but the table will hold probably 50,000 records soon and so will
>create a load on the server each time it is called.
>
>Any other ideas?
>
>Thanks once again for your help.
>
>Rgds
>
>Darren
>
>
>-----Original Message-----
>From: Jim Faucette <jimf@stripped>
>To: Darren Sweeney <darrensw@stripped>
>Cc: MySQL <mysql@stripped>
>Date: Saturday, May 29, 1999 5:32 PM
>Subject: Re: last_insert_id() - strange ??
>
>
>Darren Sweeney wrote:
>>
>> Hi
>>
>> I have a simple table ...
>>
>> CREATE TABLE itemid
>> (
>> id INT NOT NULL AUTO_INCREMENT,
>> quantity INT NOT NULL,
>> primary key(id),
>> index itemid_idx(id)
>> );
>>
>> I did a couple of simple inserts which resulted in ...
>>
>> mysql> select * from itemid;
>> +----+----------+
>> | id | quantity |
>> +----+----------+
>> |  1 |        1 |
>> |  2 |        9 |
>> |  3 |     6700 |
>> +----+----------+
>> 3 rows in set (0.00 sec)
>>
>> Fine.
>>
>> Now, all I want to do is retrieve the last inserted id but when I run the
>select I get it the same number of times as there are rows, in thid case 3
>time ... how do I get just one row?
>>
>> Here's what happened ...
>>
>> mysql> select last_insert_id() from itemid;
>
>Try it without the FROM:
>mysql> select last_insert_id();
>
>  jim...
>
>
>
>---------------------------------------------------------------------
>Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before
>posting. To request this thread, e-mail mysql-thread4146@stripped
>
>To unsubscribe, send a message to the address shown in the
>List-Unsubscribe header of this message. If you cannot see it,
>e-mail mysql-unsubscribe@stripped instead.


--
Paul DuBois, paul@stripped
Northern League Chronicles: http://www.snake.net/nl/
Thread
last_insert_id() - strange ??Darren Sweeney30 May
  • Re: last_insert_id() - strange ??Jim Faucette30 May
Re: last_insert_id() - strange ??Darren Sweeney30 May
  • Re: last_insert_id() - strange ??Paul DuBois30 May
  • Re: last_insert_id() - strange ??Graham Ashton30 May
Re: last_insert_id() - strange ??Darren Sweeney30 May
  • Re: last_insert_id() - strange ??Jim Faucette30 May