List:General Discussion« Previous MessageNext Message »
From:Darren Sweeney Date:May 30 1999 12:52am
Subject:Re: last_insert_id() - strange ??
View as plain text  
Hi again,

Solution??

Is using max(id) just as, if not more efficient? Same results ...

Thanks

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...


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