Skip to content

Instantly share code, notes, and snippets.

@paulund
Created June 3, 2013 19:58
Show Gist options
  • Save paulund/5700885 to your computer and use it in GitHub Desktop.
Save paulund/5700885 to your computer and use it in GitHub Desktop.
When you need to update a database row with the highest ID in the table. You can get the highest id by using the MAX() function but this function doesn't work in a nested select so you can't do this. UPDATE table SET name='test_name' WHERE id = (SELECT max(id) FROM table) Therefore you need to use a different way of getting the highest ID. This …
UPDATE table SET name='test_name' ORDER BY id DESC LIMIT 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment