I am attempting to do an UPDATE with a JOIN. I have two tables:
- player_tracking has a list of all
players that each user has added to
tracking. - users is the user list. each user
can set fsp_f to 1 or 0.
I want to update all rows in player_tracking for users who have fsp_f set to 1. Here is my example code:
UPDATE player_tracking AS pt
LEFT JOIN users AS u ON u.name = pt.user
SET pt.newtome = pt.newtome - 1
WHERE pt.first = 'Brett'
AND pt.last = 'Gardner'
AND pt.sport = 'mlb'
AND u.fsp_f = 1
The problem is that there are 22 rows to update, yet the UPDATE query only affects 2. Why? Is my query wrong?
Here is the data found in player_tracking pertaining to “Brett” “Gardner” “mlb”:
http://pastebin.com/kyf8SCy8
i believe that if you change the
LEFT JOINtoJOINyou will see the exact rows that get updated since you are using a field formusersin theWHEREpart of the statement.so basically you are trying to check if
u.fsp_f = 1when there could be rows that do not joinusersand therefore will have the value asNULL.Additionally it seems that the general layout of your query is not correct either, since you are joining on the
SETstatement and not in theUPDATEpart – where you instructed which table to update