Delete(删除重复但保留重复记录中的第一条记录)
--方法一:
--建立測試環境
Create Table A
(id Int,
name Varchar(10),
age Int)
Insert A Select 1, 'w', 18
Union All Select 2, 'e', 17
Union All Select 3, 'w', 18
Union All Select 4, 'e', 17
Union All Select 5, 'e', 17
Union All Select 6, 'q', 16
--測試
Select * from A
Delete from A Where id Not In (Select Min(id) As id from A Group By name,age)
Select * from A
--刪除測試環境
Drop Table A
--結果
/*
--刪除前
idnameage
1w18
2e17
3w18
4e17
5e17
6q16