我目前有两个桌子。一相当大而一适当地小。大表由表中的许多插入内容组成,其样式与小表相同。
我想将小表中的记录(如果尚未在大表中插入)插入(可能使用insert into)到大表中。
注意事项
您可以使用以下方法执行此操作not exists
:
insert into bigTable(col1, . . ., coln)
select col1, . . ., coln
from smallTable s
where not exists (select 1
from bigTable b
where b.col1 = s.col1 and b.col2 = s.col2 and . . .
);
注意:这不适用于NULL
值。好的,它确实可以“工作”,但是您将获得重复的行,这与NULL
“未知”(而不是“丢失”)的含义是一致的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句