一句sql语句删除重复记录

建一个实例表

CREATE TABLE [dbo].[User](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [nchar](10) COLLATE Chinese_PRC_CI_AS NULL,
[age] [int] NULL

) ON [PRIMARY] 

 一个sql语句删除重复记录

DELETE  FROM [USER] WHERE id  not IN ( SELECT MIN(ID) AS Id FROM [User] u GROUP BY u.[Name],u.age )  

DELETE  from [User] u where exists(select 1 from [User] where [name]=u.[name] and age=u.age and id<u.id) 

你可能感兴趣的:(sql语句)