因为一个项目导致supe_memberfield这个表中很多重复数据,数据属于完全重复,参考网上资料,有一方法
select distinct * from supe_memberfield
就可以得到无重复记录的结果集。
如果该表需要删除重复的记录(重复记录保留1条),可以按以下方法删除
select distinct * into #Tmp from supe_memberfield
drop table supe_memberfield
select * into supe_memberfield from #Tmp
drop table #Tmp
但在测试服务器上测试不能 select distinct * into #Tmp from supe_memberfield
有个替代方法
Create table supe_memberfield1 (select distinct * from supe_memberfield);
alter table supe_memberfield rename supe_memberfield5
参考网址备忘
select * from supe_memberfield
where uid in (select uid
from supe_memberfield
group by uid
having count(uid) > 1)
select * from supe_memberfield
where uid in (select uid from supe_memberfield group by uid having count(uid) > 1)
select * from supe_memberfield GROUP BY uid
http://www.phpchina.com/index.php?action-viewthread-tid-77119
http://opkeep.com/database/mysql/mysql-select-into-sql-select-into.html
MySQL查询及删除重复记录的方法
http://xielei.javaeye.com/blog/334677
PHP+MYSQL 两行Query搞定删除重复数据
http://liheyuan87.blog.sohu.com/31926761.html
http://www.linuxdiyf.com/viewarticle.php?id=47357
http://blogold.chinaunix.net/u2/72421/showart_1018947.html
http://www.zhenhua.org/article.asp?id=579
查询重复记录 select * from table GROUP BY name
只把有重复的显示出来
select * ,count(*) as nums from tab_a group by name having nums>1
方法一:(这个方法比较不错,只是自增字段会重建)
新建一个临时表
create table tmp as select * from youtable group by name
删除原来的表
drop table youtable
重命名表
alter table tmp rename youtable
方法二:(未试过)
CREATE TEMPORARY TABLE
bad_temp2(id VARCHAR(10), name VARCHAR(20))
TYPE=HEAP;
INSERT INTO bad_temp2(name) SELECT DISTINCT name FROM bad_table2;
DELETE FROM bad_table2;
INSERT INTO bad_table2(id,name) SELECT id,name FROM bad_temp2;
以上方法采用建立临时表的办法删除了 bad_table2 中 name 字段有重复的记录。
MySQL查询及删除重复记录的方法
http://www.zhaipeng.cn/2009/05/14/mysql%E6%9F%A5%E8%AF%A2%E5%8F%8A%E5%88%A0%E9%99%A4%E9%87%8D%E5%A4%8D%E8%AE%B0%E5%BD%95%E7%9A%84%E6%96%B9%E6%B3%95/
可行
http://zhidao.baidu.com/question/55601491.html
首先先创建一个临时表,然后将author表中无重复的数据拎出来,放进临时表中。
create temporary table 表名
select distinct id,name,password
from author
然后将author表中的记录全部删除。
delete from author
最后将临时表中的记录插入author表中
insert into author (id,name,password)
select id,name,password
from 临时表