Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
October 22, 2009, 1:16 am
rate this thread
Re: Is it possible to INSERT and then SELECT the inserted row in one query?
For auto_increment columns, LAST_INSERT_ID() will give you the value
for the last-inserted row *on this connection* with an auto_increment
column. Actions on other connections do not affect it, so there's
no need for locking against that possibility. If the auto_increment
column is a primary key, you can then select it using only "WHERE
id = LAST_INSERT_ID()".
can also be used to get the id for later use (e.g. inserting several
records that refer to this one, which may have auto_increment columns
of their own which would change LAST_INSERT_ID().
- » Americanas.com SALDO de TVs Com at 80% de Desconto (29798)
- — Newest thread in » MySQL Database Forum