I have the following query (user_id isn’t and can’t be primary key as there are many entries from each user depending on another column of the table). I used duplicate key but doesnt work. It still adds a new row. Any thoughts?
INSERT INTO profile (user_id, correct) VALUES(". $user_id . ", correct + 1)
ON DUPLICATE KEY UPDATE correct=correct+1
EDIT
So if row exists for this user_id, I want to go update this entry and SET correct = correct+1 and not make a new entry with user_id and correct=1 again
Try this:
Or:
If not found:
I prefer the second variant.
The first variant requires that the
user_idhas a UNIQUE constraint. (PRIMARY KEY counts.)