Created
June 3, 2013 19:58
-
-
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 …
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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