List:MySQL ODBC« Previous MessageNext Message »
From:John Bonnett Date:February 2 2011 10:23pm
Subject:RE: Retrieving last_insert_id
View as plain text  
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:jerry@stripped] 
Sent: Saturday, 22 January 2011 6:27 AM
To: myodbc@stripped
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:jerry@stripped> jerry@stripped 

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

 

Thread
Retrieving last_insert_idJerry Schwartz21 Jan
  • RE: Retrieving last_insert_idJohn Bonnett2 Feb
    • RE: Retrieving last_insert_idJerry Schwartz3 Feb
  • RE: Retrieving last_insert_idAl McNicoll3 Feb
    • RE: Retrieving last_insert_idJerry Schwartz3 Feb
      • RE: Retrieving last_insert_idAl McNicoll3 Feb
        • RE: Retrieving last_insert_idLawson K. Cronlund3 Feb
        • RE: Retrieving last_insert_idJerry Schwartz3 Feb
  • Re: RE: Retrieving last_insert_idpwr3 Feb
    • RE: RE: Retrieving last_insert_idJerry Schwartz3 Feb