[英]DB2 SQL Merge Using All Fields
我有兩個具有相同布局的文件。 我想將數據從舊文件復制到新文件並繞過/忽略重復的鍵。 使用合並語句似乎是最好的選擇,但文件有超過 50 個字段。 有沒有辦法使用類似於以下的合並:
merge into qgpl.filea as new
using(select * from qgpl.fileb) as old
on(new.key1 = old.key1 and new.key2 = old.key2)
when not matched then insert(*)
我已經嘗試了所有我能想到/找到的方法來讓插入語句正常工作,而無需輸入所有字段名稱。
謝謝。
為什么不只使用insert
?
insert into qgpl.filea
select b.*
from qgpl.fileb b
where not exists (select 1
from qgpl.filea a
where a.key1 = b.key1 and a.key2 = b.key2
);
最好的做法是列出插入的所有列,以確保沒有意外發生。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.