Sir
Sir

Reputation: 8280

INSERT with on duplicate key update

I'm having difficulty understanding the correct syntax for an insert with an on duplicate key update check.

I currently get an error with the query:

INSERT INTO users_items (q,id,uid)
ON DUPLICATE KEY UPDATE
q = q + ?, id = ?, uid = ?  

The unique key is uid + id together.

My error is:

 Syntax error or access violation: 1064 You have an error in your SQL syntax;

Upvotes: 0

Views: 627

Answers (1)

zerkms
zerkms

Reputation: 254926

VALUES is the required part (or SET or SELECT)

INSERT INTO users_items (q,id,uid)
VALUES (v1, v2, v3) -- <<< this is what you missed
ON DUPLICATE KEY UPDATE
q = q + ?, id = ?, uid = ?

Referene:

Upvotes: 1

Related Questions