Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
只有当新值不为空时,我才必须合并两个表并更新重复键。我尝试了下面的代码但没有成功有人可以帮忙吗?谢谢!
INSERT INTO table1 SELECT * FROM temp ON DUPLICATE KEY UPDATE table1.tel = coalesce(temp.tel,table1.tel), table1.fax = coalesce(temp.fax,table1.fax)
我认为您的问题可能是您在更新子句中引用值的方式。以下可能会更好:
INSERT INTO table1 SELECT * FROM temp ON DUPLICATE KEY UPDATE table1.tel = coalesce(values(tel),tel), table1.fax = coalesce(values(fax),fax)