delete MemberInfo where ID not in (
select max(ID) from MemberInfo group by MemberName, MemberAddress)
select max(ID) from MemberInfo group by MemberName, MemberAddress)
not in的效率可能会低些,但因为是直接操作数据库,所以这并不重要.这个句子还是非常的简单有效的.
在真正的删除操作前,通常会先了解一下重复记录的情况.可以使用下面的句子:
SELECT COUNT(MemberName) AS TheCount, MemberName, MemberAddress
FROM MemberInfo
GROUP BY MemberName, MemberAddress
HAVING (COUNT(*) > 1)
FROM MemberInfo
GROUP BY MemberName, MemberAddress
HAVING (COUNT(*) > 1)