这是我的问题:下面有两个示例表,我尝试根据匹配 ID 从表一更新并插入到表二。但不工作。当不存在时添加到表 2
表1
ID DESC
1. 1 one
2. 2 two
3. 3 three
4. 4 four
表2
ID DESC
1. 1 ones
2. 2
3. 3 three
INSERT INTO
notif_test(ntfy_ttl,ntfy_desc,ntfy_typ,beg_dt,del_nbr,crt_ts,crt_nbr,
upd_ts,upd_nbr) select
ntfy_ttl,ntfy_desc,ntfy_typ,beg_dt,del_nbr,crt_ts,crt_nbr,upd_ts,upd_nbr
from notif_dump
ON DUPLICATE KEY UPDATE ntfy_desc = VALUES(ntfy_desc)
最佳答案
查看您的数据,您似乎正在寻找 DESC 为空的值的更新
update table1 a
inner join table2 b
on a.id = b.id
set a.desc = b.desc
where a.desc is null
关于mysql - 使用匹配 ID 将数据从表 1 插入和更新到表 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47058655/