Does anybody know a method of updating a sinlge value where the id=MAX(id)
The following query does not work, and it appears the mySQL does not allow the ORDER BY for UPDATE.
UPDATE table SET foo='value' ORDER BY id DESC LIMIT 1
Thanks
I'm not quite sure why you would want to order by on an update statement?!! Order by is a select operand.
Do it in two statements:
SELECT MAX(id) AS max FROM table; UPDATE table SET foo='value' WHERE id = '$max';
MySQL doesn't support sub-selects so you can't do it in one statement.
-- Nick Gushlow.
Don't forget to lock the table first, otherwise someone else may be able to insert a new row between your first and second statements.