create a mysql record if it doesnt exist, else update it

后端 未结 4 1426
猫巷女王i
猫巷女王i 2021-01-27 13:35

I would like to modify this MySQL query to insert the row only if it does not exist. Otherwise, I would like to update the existing row.



        
4条回答
  •  遥遥无期
    2021-01-27 14:15

    Yeah, use ON DUPLICATE KEY UPDATE

    for that. Here is an example:

    INSERT INTO  (, ) VALUES (, )
    ON DUPLICATE KEY UPDATE  = 'update CONTENT';
    
    
    

    important is the primary key (underlined in phpMyAdmin table).

    提交回复
    热议问题