create table A
(
userID int identity(1,1),
userName varchar(20),
userPwd varchar(20),
userEmail varchar(50)
)
insert into A(userName,userpwd) 'qin','qin' union all select 'qin','qin1' union all select 'qin','qin1'
select * from A
--method one
delete from A where userid not in(select min(userid) as userid from A group by username ,userpwd)
--method two
delete from A where exists (select * from A b where a.username = b.username and a.userpwd = b.userpwd and a.userid
--method three
delete from a where userid not in(select min(userid) from A b where a.username = b.username and a.userpwd = b.userpwd and a.userid > b.userID)
select * from A
drop table A
|