查找重复项并将它们插入到单独的表中

时间:2013-04-13 12:17:03

标签: sql insert duplicates

我有一张桌子

Id int
Post code int
Suburb varchar
State varchar

我需要能够找到合并的(post code, suburb, state)

的副本

将它们插入到一个记录错误数据的绝望表中

Eg
Id int
Post code int
Suburb varchar
State varchar

1 个答案:

答案 0 :(得分:2)

INSERT INTO IncorrectResults (PostCode, Suburb, State)
SELECT PostCode, Suburb, State
FROM MyTable
GROUP BY PostCode, Suburb, State
HAVING COUNT(*) > 1