Created
April 4, 2011 20:44
-
-
Save kurko/902390 to your computer and use it in GitHub Desktop.
Let's say we want to calculate something, i.e. increase a counter
This file contains 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
# this doesn't work | |
"INSERT INTO table1 (field1) VALUE( (SELECT field1 FROM table1 LIMIT 1)+1 )" | |
# "You can't specify target table 'table1' for update in FROM clause" | |
# but this works | |
"INSERT INTO table1 (field1) VALUE( (SELECT field1 FROM (SELECT field1 FROM table1 LIMIT 1))+1 )" | |
# the FROM statement becomes just a repetition of the subquery. | |
# Thus, MySQL creates the temporary table with no problem. | |
# I understand this change isolates the INSERT's table1 from the SELECT's, | |
# so MySQL doesn't think it's the same, but isn't this funny, redundant and tricky? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This applies to UPDATE as well.