ON DUPLICATE KEY UPDATE with WHERE condition

有些话、适合烂在心里 提交于 2019-12-04 05:01:45

Using IF() should work, though it's not nice:

INSERT INTO table1 SET 
 field1=aa, 
 field2=bb, 
 field3=cc 
ON DUPLICATE KEY UPDATE SET 
 field1 = IF( field4 = zz, aa, field1 ),
 field2 = IF( field4 = zz, bb, field2 ),
 field3 = IF( field4 = zz, cc, field3 )

Only update the fields with new values if the condition is met, otherwise keep the old ones.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!