Quote
Yes, there is only 1 row in the table.
Good to hear.
You'd be surprised how many people pick up a piece of code like that and throw it against a
million row table (by mistake, hopefully) and then wonder why it's so slow!
Quote
the field that is incremented is of type int. (Not an autoincrement). Does that make a difference ?
Not at all.
int is what it should be.
I was
trying (and clearly failing; apologies) to point out that your use of the last_insert_id() function as part of your original update statemetn was incorrect.
You need
that function when you insert, say, a new "Parent" record with an auto-increment key and need to re-use the newly-generated ID value of that "Parent" record to insert a related, "Child" record, something like this:
insert
into parent ( name ) /* No ID value supplied, so MySQL will generate one */
values ( 'Fred' )
;
insert
into child ( parent_id, name ) /* No ID value supplied, so MySQL will generate one, but only after ... */
values ( last_insert_id(), 'Pebbles' ) /* Use the ID just generated for Fred */
;
select *
from parent ;
+----+------+
| id | name |
+----+------+
| 6 | Fred |
+----+------+
select *
from child ;
+----+-----------+---------+
| id | parent_id | name |
+----+-----------+---------+
| 77 | 6 | Pebbles |
+----+-----------+---------+
Regards, Phill W.