MySql中删除重复垃圾记录
2016-03-24 17:35
507 查看
1. 将需要的数据去重(利用group by)查询出
2. 删除原表中不再里面的记录
a. 重复记录由多个字段判断
查询出重复记录:
select id from user group by userName, password having count(*) >=1);
删除
delete from user where id not in (select id from (select id from user group by userName, password having count(*) >=1) u);
b. 重复记录由一条字段组成
查询出重复记录:
select id from user group by id having count(*) > =1;
删除
delete from user where id not in (select id from (select id from user group by id having count(*) > =1) u);
引用临时表是为了防止mySql中的You can't specify target table 'user' for update in FROM clause错误
2. 删除原表中不再里面的记录
a. 重复记录由多个字段判断
查询出重复记录:
select id from user group by userName, password having count(*) >=1);
删除
delete from user where id not in (select id from (select id from user group by userName, password having count(*) >=1) u);
b. 重复记录由一条字段组成
查询出重复记录:
select id from user group by id having count(*) > =1;
删除
delete from user where id not in (select id from (select id from user group by id having count(*) > =1) u);
引用临时表是为了防止mySql中的You can't specify target table 'user' for update in FROM clause错误
相关文章推荐
- MySQL性能优化
- MySql WorkBench通过表生成表关系图
- mysql索引
- 关于MYSQL的行列转换
- MySQL性能优化的最佳20+条经验
- 详解MySQL中的分组查询与连接查询语句
- MySQL复制之深入理解binlog_format及表字段顺序的重要性
- mysql 修改密码
- mysql日志开启
- mysql innodb 引擎内存分配项
- MySQL中的基本查询语句学习笔记
- 解决wamp集成的mysql和已有的mysql冲突问题
- 【MySQL】性能优化之 覆盖索引
- MySQL 存储过程和存储函数示例
- mysql中set autocommit=0与start transaction区别
- Mysql瘦身及双机热备(ab复制)方案:
- mysql集群安装
- mysql数据库表的基本操作
- MySQL性能优化的最佳20+条经验(1)
- MySQL性能优化之参数配置