0

I have a table, that stores words, there are tree columns id,word and count, word is unique key.

I just want to add +1 to count if word is already insterted. I couldnt find any sql statements,(i might not know what to search on google)

I want to add +1 to count column when i am inserting new data to word. I am not sure about it requires an unique column for this operation.

Can you help me guys? Regards!

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
YigitOzdemir
  • 95
  • 1
  • 13

1 Answers1

3
INSERT INTO tablename (word, count)
VALUES ("TheWord", 1)
ON DUPLICATE KEY UPDATE count = count + 1

I believe this is what you are looking for. Is there any reason to have the id column if word is unique?

Ignacio
  • 5,300
  • 1
  • 15
  • 10