mysql-python: How can I retrieve the ID of the last record I added?

Oleg Broytmann phd at phd.pp.ru
Fri Sep 28 09:44:40 EDT 2001


On Fri, Sep 28, 2001 at 03:46:27PM +0200, Gabriel Ambuehl wrote:
> Hello,
> I've got a MySQL table which has got an id field that is declared as
> auto_increment so every record added gets its own unique id. So far
> so
> good, but how can I fetch the id of the last record added? I know I
> can do some SELECT to gather the ID but if there are two completely
> identical records, which is possible, it won't do me any good. So is
> there some library function to reliably retrieve the id of the last
> record I inserted into the table?

   SELECT LAST_INSERT_ID()

Oleg.
---- 
     Oleg Broytmann            http://phd.pp.ru/            phd at phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.




More information about the Python-list mailing list