对没有索引的字段进行查询重复时如果使用select name from table where name in(select name from table group by name having count(name)>1)这类查询,效率非常低,是不可取的,下面给出替代步骤:
1.根据重复记录创建临时表
create table temptable as (
select title from video
GROUP BY title HAVING count(title) >1
);
2.查询重复数据
select a.* from temptable t,video a where a.title=t.title;
下面给出实际中我使用的删除重复数据的脚本,供参考:
create table temptable as ( select MAX(id) as id from video GROUP BY title HAVING count(title) >1 ); delete from video where id in (select id from temptable) order by id ; drop table temptable;