List:General Discussion« Previous MessageNext Message »
From:Dan Nelson Date:September 19 2002 5:59pm
Subject:Re: Auto Increment ID of Inserted Row
View as plain text  
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
Thread
Auto Increment ID of Inserted RowTim Davis19 Sep
  • Re: Auto Increment ID of Inserted RowPaul DuBois19 Sep
  • Re: Auto Increment ID of Inserted RowSteven Kreuzer19 Sep
    • Re: Auto Increment ID of Inserted RowPaul DuBois19 Sep
    • Re: Auto Increment ID of Inserted RowRodney Broom19 Sep
    • Re: Auto Increment ID of Inserted RowDan Nelson19 Sep
RE: Auto Increment ID of Inserted RowMichael Tam19 Sep