要列出所有異常:
SELECT name, count(*) FROM TableA GROUP BY name HAVING count(*) > 1;
有解決刪除複本和你的路徑將在很大程度上取決於你的DUP數量的幾種方法。
請參閱this SO問題的方式從您的表中刪除這些。
這裏是我只要有解決方案:
-- Setup for example
create table people (fname varchar(10), lname varchar(10));
insert into people values ('Bob', 'Newhart');
insert into people values ('Bob', 'Newhart');
insert into people values ('Bill', 'Cosby');
insert into people values ('Jim', 'Gaffigan');
insert into people values ('Jim', 'Gaffigan');
insert into people values ('Adam', 'Sandler');
-- Show table with duplicates
select * from people;
-- Create table with one version of each duplicate record
create table dups as
select distinct fname, lname, count(*)
from people group by fname, lname
having count(*) > 1;
-- Delete all matching duplicate records
delete people from people inner join dups
on people.fname = dups.fname AND
people.lname = dups.lname;
-- Insert single record of each dup back into table
insert into people select fname, lname from dups;
-- Show Fixed table
select * from people;
如果這兩個名稱不相等,只要不違反重複的約束。我不會在這裏跟隨你。如果數據是損壞的,你應該糾正它。 – crunchdog 2010-02-16 15:36:52
當我導出並重新導入數據時,它們是平等的。 「如果數據是腐敗的,你應該糾正它。」我如何找到損壞的數據?我無法搜索廣場。 – 2010-02-16 15:48:27
對不起,如果我的描述是不準確的,但問題是很奇怪的。 – 2010-02-16 15:56:08