3
INSERT INTO GameScoreTotal (
    `GameName`
    , `OverallScore`
    , `GraphicsScore`
    , `StoryScore`
    , `GameplayScore`
    , `TimeScore`
    )
VALUES (
    'HomeFront'
    , '1'
    , '1'
    , '1'
    , '1'
    , '5'
    )
WHERE GameName = 'HomeFront'
    ON DUPLICATE KEY

UPDATE OverallScoreTotal = OverallScoreTotal + '1'
    , GraphicsTotal = GraphicsTotal + '1'
    , StoryTotal = StoryTotal + '1'
    , GameplayTotal = GameplayTotal + '1'
    , TimeTotal = TimeTotal + '1'
    , RatingCount = RatingCount + 1;

I am trying to update GameScoreTotal If we have something there otherwise insert. Any ideas?

2 Answers 2

7
  • you need to define key on GameName name, (a unique or primary key should do)
  • remove WHERE clause from the insert statement

query,

INSERT INTO GameScoreTotal ( `GameName` , `OverallScore` , `GraphicsScore`
                           , `StoryScore` , `GameplayScore`  , `TimeScore` )
VALUES ( 'HomeFront' , 1  , 1 , 1 , 1 , 5 )
    ON DUPLICATE KEY
UPDATE OverallScoreTotal = OverallScoreTotal + 1
     , GraphicsTotal = GraphicsTotal + 1
     , StoryTotal = StoryTotal + 1
     , GameplayTotal = GameplayTotal + 1
     , TimeTotal = TimeTotal + 1
     , RatingCount = RatingCount + 1;

SOURCE

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

Comments

0

Lookup REPLACE INTO instead of INSERT INTO.

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.