So I'm trying to write an sql query to be execute from php to count number of downloads of a files. I have a table id,name,count and I want it to check if the name exists and increment count else to insert a new row.
I was trying to use if exists but that didn't work so now I'm trying to use the on duplicate key update statement. I inserted a row with the name lemons as a test case. I keep getting the error with my syntax near the WHERE statement. Am I approaching this right?
INSERT INTO `table` (`name`, `count`)
VALUES ('lemons',1) ON DUPLICATE KEY
UPDATE `count` = `count`+1
WHERE `name` = 'lemons';
Aucun commentaire:
Enregistrer un commentaire