List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:September 16 1999 3:07am
Subject:Re: LAST_INSERT_ID question
View as plain text  
At 10:01 PM -0500 9/15/99, a rancid amoeba wrote:
>..but first, can anyone recommend a book or website that is more
>SQL style-oriented than syntax-oriented? For example, the MySQL
>manual and O'Reilly book cover the syntax of an INSERT statement,
>but don't touch on the finesse of properly updating multiple linked
>tables (sometimes I feel like I'm dealing with the chicken and the
>egg instead of mere relational tables).
>Now for the techie question. I'm inserting stuff into multiple linked
>tables (by batch file if that makes any difference) and LAST_INSERT_ID
>doesn't seem to be doing anything. I don't know if I'm using it
>improperly or what. Here's an example:
>INSERT INTO LabelLocation VALUES (NULL, 'Palo Alto', 'CA', '', 'US');
>INSERT INTO RecordLabel VALUES (NULL, 'This Label','This Label',

Your problem is that you have LAST_INSERT_ID() in quotes, so it's
a string.  The string undergoes string-to-number conversion when
MySQL inserts it into the second table.  Result: 0.

Paul DuBois, paul@stripped
LAST_INSERT_ID questiona rancid amoeba16 Sep
  • Re: LAST_INSERT_ID questionPaul DuBois16 Sep
  • Re: LAST_INSERT_ID questionJames Manning16 Sep