11-11-2014, 10:23 AM | #1 | ||
Morgado's Favorite Forum Fascist
Join Date: Oct 2000
Location: Greensboro, NC
|
MySQL UPDATE statement question
I'm trying to apply a simple weighting to update a column in a MySQL table as follows:
Code:
It's giving me "You can't specify target table 'fof7_rookies' for update in FROM clause." I suppose that I can add a column, write the value to that column, set adjustedgrade to equal that column, then delete the column, but I'm guessing there's a more straightforward way to do this. Little help?
__________________
The media don't understand the kinds of problems and pressures 54 million come wit'! |
||
11-11-2014, 10:28 AM | #2 |
Death Herald
Join Date: Nov 2000
Location: Le stelle la notte sono grandi e luminose nel cuore profondo del Texas
|
What happens when you try this?
Code:
__________________
Thinkin' of a master plan 'Cuz ain't nuthin' but sweat inside my hand So I dig into my pocket, all my money is spent So I dig deeper but still comin' up with lint |
11-11-2014, 10:32 AM | #3 |
Head Coach
Join Date: Dec 2002
Location: Maryland
|
something like:
UPDATE fof7_rookies r, fof7_positionweights w SET r.adjustedgrade = round(r.adjustedgrade * w.weight, 0) WHERE r.position_group = w.position_group AND r.rookieyear < 2042 OR UPDATE fof7_rookies JOIN fof7_positionweights w on w.positiongroup = r.position_group) SET r.adjustedgrade = round(r.adjustedgrade * w.weight,0) WHERE r.rookieyear < 2042 I think. ETA: if not, look at this, this should help - http://www.mysqltutorial.org/mysql-update-join/
__________________
null Last edited by cuervo72 : 11-11-2014 at 10:34 AM. |
11-11-2014, 10:42 AM | #4 |
Death Herald
Join Date: Nov 2000
Location: Le stelle la notte sono grandi e luminose nel cuore profondo del Texas
|
actually, yeah, cuervo's second query should be what you want for MySQL, except for the extraneous ) at the end of the 2nd line, and the missing alias of r for the first line
__________________
Thinkin' of a master plan 'Cuz ain't nuthin' but sweat inside my hand So I dig into my pocket, all my money is spent So I dig deeper but still comin' up with lint |
11-11-2014, 10:42 AM | #5 |
Morgado's Favorite Forum Fascist
Join Date: Oct 2000
Location: Greensboro, NC
|
Cartman's solution gave me the same error. Trying cuerv's now...
__________________
The media don't understand the kinds of problems and pressures 54 million come wit'! |
11-11-2014, 10:45 AM | #6 |
Morgado's Favorite Forum Fascist
Join Date: Oct 2000
Location: Greensboro, NC
|
Cuervo suggestion 1 appears to have worked. Thanks to both of you!
__________________
The media don't understand the kinds of problems and pressures 54 million come wit'! |
11-11-2014, 01:04 PM | #7 |
Head Coach
Join Date: Dec 2002
Location: Maryland
|
__________________
null |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
|
|