Don
Don

Reputation: 193

UPDATE field of last entry SQL

I like to update the field "filepath" of my table "imagedata" of the last entry made?

UPDATE `imagedata` SET `filepath`='sdsd' WHERE `id` = MAX(imagedata.id);

Somehow my synax ist not right it says:

Invalid use of group function`

what do i do wrong?

Upvotes: 1

Views: 5069

Answers (2)

Shai Mishali
Shai Mishali

Reputation: 9392

If you use an AUTO_INCREMENT column, You could try

UPDATE `imagedata` SET `filepath`='sdsd' WHERE `id` = LAST_INSERT_ID();

Upvotes: 1

Nicola Cossu
Nicola Cossu

Reputation: 56397

UPDATE `imagedata` 
SET `filepath`='sdsd' 
order by id desc limit 1

Another alternative:

UPDATE `imagedata` 
SET `filepath`='sdsd' 
where id = (select * from (select max(id) from imagedata) as t)

Upvotes: 4

Related Questions