MySQL — Update if exists else insert with two keys

后端 未结 4 677
栀梦
栀梦 2021-01-03 03:17

I have a table with fields foreign_key_id | value1 | value2, and I want to update value2 if I have a match for foreign_key_id and value1.

If foreign_key_id or value

4条回答
  •  滥情空心
    2021-01-03 03:35

    Best option: Use REPLACE instead of INSERT or UPDATE. It depends on the use of a primary key or unique key.

提交回复
热议问题