MySQL: INSERT and return?by Spidy (Chaplain)
|on Jul 04, 2006 at 18:31 UTC||Need Help??|
Spidy has asked for the
wisdom of the Perl Monks concerning the following question:
Greetings, Fellow Monks,
Recently, I've been doing some work on a MySQL system that involves, among other things, inserting rows into a certain table. In order to keep the table organized, we have it arranged like this:
Now, this is all well and good, and it serves our purposes fine. We use the auto_increment attribute of the id column in order to track each entry within our table. To insert something, we use this query:
And after this, I need to retrieve the id value for the row that we just inserted. I know this can be accomplished with a simple select query after the insertion, but I'm wondering: is there any way for me to reduce this to a single query, that will insert the row and return the id for the row that was just inserted?