1

I have a table with these columns: Player_name | Item_name | Amount

I do not know how to perform this conditional INSERT:

INSERT INTO Needed_items(Player_name,Item_name) VALUES('foo','foo');

if Player_name and Item_name already exist, so if a Player already owns a given item, I need to increment Amount field, else I need to insert a new row into the table. Thanks for the help

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Luca Maltagliati
  • 102
  • 1
  • 12

1 Answers1

0

Try something like this:

INSERT INTO Needed_items(Player_name,Item_name) VALUES('foo','foo')
ON DUPLICATE KEY UPDATE Amount=Amount+1
monami
  • 594
  • 2
  • 9
  • 32