0
UPDATE default_weekly_stats s 
INNER JOIN default_profiles p
ON p.user_id = s.user_id
WHERE (default_profiles.opid = 0 OR default_profiles.opid IS NULL) 
    AND s.week = `1`
    AND s.correct_picks = `4`
SET s.rank = 1

That's my query and I'm getting an error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE (default_profiles.opid = 0 OR default_profiles.opid IS NULL) AND s.week = ' at line 1

The syntax looks right to me, but clearly I'm missing something. Any ideas what?

1
  • have you tried leaving out the backticks? Commented Sep 6, 2013 at 15:10

2 Answers 2

3

WHERE comes after SET

UPDATE default_weekly_stats s 
INNER JOIN default_profiles p ON p.user_id = s.user_id 
SET s.rank = 1
WHERE (default_profiles.opid = 0 OR default_profiles.opid IS NULL) 
AND s.week = 1 
AND s.correct_picks = 4 

And as @Chad mentioned: Leave the backticks. You could use quotes but don't need any delimiter for numbers.

Sign up to request clarification or add additional context in comments.

1 Comment

He also does not need backticks if rank, week and correct_picks are of type int.
3

Look at the UPDATE Syntax

Try this:

UPDATE
  default_weekly_stats s
    INNER JOIN default_profiles p
      ON p.user_id = s.user_id 
SET s.rank = 1
WHERE (default_profiles.opid = 0 OR default_profiles.opid IS NULL)
  AND s.week = `1`
  AND s.correct_picks = `4`

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.