php - How can I add to row with highest primary key?
I have a database, with a column I would like to update where the row is the most recently generated one, after searching for a while I found this solution
UPDATE data SET Tricked = 'Affirmative' WHERE Identification = (SELECT MAX(Identification) FROM data);
However this didn't work, I received no errors but it did nothing. What about it isn't allowing it to work?
Answer
Solution:
MySQL is objecting to your use of the
SELECT
statement in the where clause on the table you're updating. You should see a response like this:Error Code: 1093. You can't specify target table 'data' for update in FROM clause
PHP solutions involving the
last_insert_id
only work for the lifetime of the session, and then only if no other user is inserting records, so won't be reliable.Try this: