用SQL删除重复记录的N种方法
例如:
id name value
1 a pp
2 a pp
3 b iii
4 b pp
5 b pp
6 c pp
7 c pp
8 c iii
id是主键
要求得到这样的结果
id name value
1 a pp
3 b iii
4 b pp
6 c pp
8 c iii
方法1
delete YourTable
where [id] not in (
select max([id]) from YourTable
group by (name + value))
方法2
delete a
from 表 a left join(
select id=min(id) from 表 group by name,value
)b on a.id=b.id
where b.id is null
Access 修改如下
min 和 max 比较大小后删除
delete from 表 where [id] not in (select min([id]) from 表 group by 字段1,字段2)
转自:http://blog.csdn.net/jeefchen/archive/2009/06/05/4246110.aspx