MySQL on duplicate key update

前端 未结 2 821
时光取名叫无心
时光取名叫无心 2021-01-02 13:26

If I have query like this, how can I refer to values I have already given in update statement, so that I don\'t need to insert same data to query again? Example I would like

2条回答
  •  北海茫月
    2021-01-02 13:32

    In PHP I do this to solve the issue:

    $fields = "a = 1, b = 2, c = 3";
    $sql = "INSERT INTO some_table SET id = $id, $fields ON DUPLICATE KEY UPDATE $fields";
    mysql_query($sql);
    

提交回复
热议问题