MySQL select last record and update it

devs3
Devs3
Published on Apr, 17 2024 1 min read 1 comments
image

I want to select the last record in the table and update its name.

Explain

 

UPDATE item 
SET name = (SELECT name FROM pds
            WHERE id = 9)
WHERE id=(SELECT id ORDER BY id DESC LIMIT 1);

However, when executing name is changed for all the records.

Tried also:

Explain

 

UPDATE item 
SET name = (SELECT name FROM pds
            WHERE id = 9)
WHERE id=(SELECT id FROM item ORDER BY id DESC LIMIT 1);
1 Answers

Mahabubur Rahman Apr 17, 2024 - 05:21 AM