MySQL “good” way to insert a row if not found, or update it if it is found

后端 未结 6 1528
小蘑菇
小蘑菇 2020-12-08 11:44

Very often, I want to run a query on one of my users where I want a row stored and associated with that user, in a 1-to-1 relationship. So let\'s say (this is just an arbit

6条回答
  •  悲&欢浪女
    2020-12-08 11:58

    an example of how I have used ON DUPLICATE KEY UPDATE: INSERT INTO registry (name, value) VALUES ('" . $key . "', '" . $val . "') ON DUPLICATE KEY UPDATE value= '" . $val . "'"

提交回复
热议问题