List:MySQL ODBC« Previous MessageNext Message »
From:Jerry Schwartz Date:February 3 2011 1:45am
Subject:RE: Retrieving last_insert_id
View as plain text  
>-----Original Message-----
>From: Bonnett, John [mailto:John.Bonnett@stripped]
>Sent: Wednesday, February 02, 2011 5:24 PM
>To: jerry@stripped; myodbc@stripped
>Subject: RE: Retrieving last_insert_id
>
>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.
>
[JS] Unfortunately, trying to SELECT LAST_INSERT_ID() as a pass-through query 
from Access gave me results I did not understand. I don't know if your way 
would work. I basically don't know what constitutes a "connection" in this 
particular environment.

In any case, I just did away with this redundant field. That might not have 
been elegant, but it was effective and efficient.

Regards,

Jerry Schwartz
Global Information Incorporated
195 Farmington Ave.
Farmington, CT 06032

860.674.8796 / FAX: 860.674.8341
E-mail: jerry@stripped
Web site: www.the-infoshop.com



>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