How to bulk update mysql data with one query?

后端 未结 4 959
半阙折子戏
半阙折子戏 2020-12-01 05:21
$query = mysql_query(\"UPDATE a SET fruit = \'**apple**\' WHERE id = \'**1**\' \");
$query2 = mysql_query(\"UPDATE a SET fruit = \'**orange**\' WHERE id = \'**2**\'          


        
4条回答
  •  有刺的猬
    2020-12-01 05:41

    I found a following solution:

    INSERT into `table` (id,fruit)
        VALUES (1,'apple'), (2,'orange'), (3,'peach')
        ON DUPLICATE KEY UPDATE fruit = VALUES(fruit);
    

    Id must be unique or primary key. But don't know about performance.

提交回复
热议问题