Front Office Football Central  

Go Back   Front Office Football Central > Main Forums > Off Topic
Register FAQ Members List Calendar Mark Forums Read Statistics

Reply
 
Thread Tools
Old 11-11-2014, 10:23 AM   #1
Ben E Lou
Morgado's Favorite Forum Fascist
 
Join Date: Oct 2000
Location: Greensboro, NC
Question MySQL UPDATE statement question

I'm trying to apply a simple weighting to update a column in a MySQL table as follows:

Code:
update fof7_rookies set adjustedgrade= (SELECT round(adjustedgrade*w.weight,0) FROM fof7_rookies r JOIN fof7_positionweights w on w.positiongroup=r.position_group) where rookieyear<2042

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'!

Ben E Lou is offline   Reply With Quote
Old 11-11-2014, 10:28 AM   #2
cartman
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:
update fof7_rookies set adjustedgrade= (SELECT round(adjustedgrade*w.weight,0) as weighting FROM fof7_rookies r JOIN fof7_positionweights w on w.positiongroup=r.position_group) where rookieyear<2042
__________________
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
cartman is offline   Reply With Quote
Old 11-11-2014, 10:32 AM   #3
cuervo72
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.
cuervo72 is offline   Reply With Quote
Old 11-11-2014, 10:42 AM   #4
cartman
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
cartman is offline   Reply With Quote
Old 11-11-2014, 10:42 AM   #5
Ben E Lou
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'!
Ben E Lou is offline   Reply With Quote
Old 11-11-2014, 10:45 AM   #6
Ben E Lou
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'!
Ben E Lou is offline   Reply With Quote
Old 11-11-2014, 01:04 PM   #7
cuervo72
Head Coach
 
Join Date: Dec 2002
Location: Maryland
__________________
null
cuervo72 is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is On
Forum Jump


All times are GMT -5. The time now is 01:28 PM.



Powered by vBulletin Version 3.6.0
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.