如何在SQL的INSERT语句里屏蔽重复数据

2024-12-21 14:54:50
推荐回答(2个)
回答1:

假如你的T1表是这样的,主键字段叫NEWID,还有其他几个字段叫F1,F2,F3
T2表和T1表结构一样,那么
insert into T2 select min(NEWID),F1,F2,F3 from T1 group by F1,F2,F3

回答2:

insert into t1(newid,filed1,filed2)
select t2.newid,t2.filed1,t2.filed2
from t2,t1 as t3
where t2.filed1<>t3.filed1 and t2.filed2<>t3.filed2