2017-06-06 30 views
0

更新多一個行我有一個數據庫表,如:如何在mysql中

 +---+-------------+ 
     |id |ship_method | 
     +---+-------------+ 
     | 1 |freeshipping |  
     | 1 | flatrate | 
     | 2 | DHL  | 
     | 3 | matrixrate | 
     | 1 | courier | 
     +---+-------------+ 

所以,我要根據選擇的多選項更新從前端的形式ship_method。 例如:如果Id1選擇自由發送,DHL,矩陣速率,則應更新ship_method的相應值。

什麼是mysql查詢更新在這種情況下。我試過,但無法找到如何一次更新這樣的多行。

+0

刪除以前的數據,並插入新的從表中的所有刪除其中id = 1;插入到table_name值(1,'freeshipping')....... – JYoThI

回答

1

刪除以前的數據,並插入新的全

delete from table where id=1; 
insert into table_name(id,ship_method) values(1,'freeshipping'),(1,'DHL'),(1,'matrixrate');