RE: Retrieving last_insert_id

"Bonnett, John" <[email protected]> Thu, 3 Feb 2011 08:53:52 +1030
Newsgroups gmane.comp.db.mysql.odbc
Message-ID <[email protected]>
If I understand you correctly you already have the the last inserted ID
in another column in the same table so you just need to copy it. You
need to make sure you only update the row you just added though. This
should do it -

UPDATE <table> SET <other column> = <primary ID column>
WHERE <primary ID column> = LAST_INSERT_ID();

You need to do that immediately after the insert on the same connection
for the value of the last insert ID to be correct.

John Bonnett

-----Original Message-----
From: Jerry Schwartz [mailto:[email protected]] 
Sent: Saturday, 22 January 2011 6:27 AM
To: [email protected]
Subject: Retrieving last_insert_id

I have an auto_increment field in my table, but I need to set another
field to the same value. (Please don't ask why.)

 

It seems I would need to insert the record, and then update it; but I
haven't figured out how to get the value of last_insert_id().

 

Any ideas?

 

Regards,

 

Jerry Schwartz

Global Information Incorporated

195 Farmington Ave.

Farmington, CT 06032

 

860.674.8796 / FAX: 860.674.8341

E-mail:  <mailto:[email protected]> [email protected] 

Web site:  <http://www.the-infoshop.com/> www.the-infoshop.com

 


-- 
MySQL ODBC Mailing List
For list archives: http://lists.mysql.com/myodbc
To unsubscribe:    http://lists.mysql.com/[email protected]