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?




MySQL is objecting to your use of theSELECT 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 thelast_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:

  SET Tricked='Affirmative' 
  ORDER BY Identification DESC

People are also looking for solutions to the problem: how to send mysql fetch records php page via email


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.