create table DistinctOrNot
(id int primary key ,name nvarchar(20))
insert into DistinctOrNot
select 1,'A'
union all
select 2,'B'
union all
select 3,'AB'
union all
select 4,'AB'
union all
select 5,'BC'
select * from DistinctOrNot
---查出重複記錄的數據
select [name] from DistinctOrNot
where [name] in (select [name] from DistinctOrNot group by [name] having count(*)>1 )
---過濾重複記錄的數據
select * from DistinctOrNot
where id in (select max(id) from DistinctOrNot group by [name])
---刪除重複的記錄
delete from DistinctOrNot where [name] in (select [name] from DistinctOrNot group by [name] having count(*)>1 )