//每一个功能只要一句来实现?能不能用一句要看你重复的程度了.因为你没给出具体数据样例. 假如你的一个表t,其中 content字段重复了,id不重复1.挑出重复记录(一句) select a.* from t a join (select content,count(*) from t group by content having count(*)>1 ) b on a.content=b.content 2.删除重复记录(一句) delete from [t] where [id] not in (select min([id]) from [t] group by [content])
Delete a from tabel a, (Select max(字段名) c from table) b where a.字段名<>b.c
1.挑出重复记录(一句)或者select * from t where content in (select content from t group by content having count(*)>1)
//列表不重复某字段的记录ID 不好意思,这个要求没看到 假如有如下数据content id a 1 a 2 a 3 b 4 c 5要求相同content取id小的 content id a 1 b 4 c 5 则 select * from t a where not exists (select 1 from t where content=a.content and id<a.id) 要求相同content取id大的 select * from t a where not exists (select 1 from t where content=a.content and id>a.id) content id a 3 b 4 c 5
delete a from t AS a where exists(select 1 from t where 主键 = a.主键 and a.id < id)
假如你的一个表t,其中 content字段重复了,id不重复1.挑出重复记录(一句)
select a.* from t a
join
(select content,count(*) from t group by content having count(*)>1 ) b
on a.content=b.content
2.删除重复记录(一句)
delete from [t] where [id] not in (select min([id]) from [t] group by [content])
(Select max(字段名) c from table) b
where a.字段名<>b.c
where content in
(select content from t group by content having count(*)>1)
不好意思,这个要求没看到
假如有如下数据content id
a 1
a 2
a 3
b 4
c 5要求相同content取id小的
content id
a 1
b 4
c 5
则
select * from t a
where not exists
(select 1 from t where content=a.content and id<a.id)
要求相同content取id大的
select * from t a
where not exists
(select 1 from t where content=a.content and id>a.id)
content id
a 3
b 4
c 5
delete a from t AS a
where exists(select 1 from t where 主键 = a.主键 and a.id < id)