加入收藏 | 设为首页 | 会员中心 | 我要投稿 百客网 - 域百科网 (https://www.yubaike.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

Mysql数据重复问题处理

发布时间:2022-09-30 12:52:47 所属栏目:MySql教程 来源:
导读:  当一某个字段重复判断重复时 :查询重复数据 重复取id最小值

  select table,min(id)

  from table

  where “字段” = 'xx'

  group by “重复字段” hav
  当一某个字段重复判断重复时 :查询重复数据 重复取id最小值
 
  select table,min(id)
 
  from table
 
  where “字段” = 'xx'
 
  group by “重复字段” having count(1) > 1 ;
 
  查询影响条数
 
  select * from table
 
  where " 字段"= 'xx'
 
  and id not in
 
  (select min(id)
 
  from table
 
  where "字段" = 'xx'
 
  MySQL 处理重复数据_处理数据库中重复数据_mysql 取出重复数据
 
  group by "重复字段" having count(1) > 1 )
 
  and "重复字段" in
 
  (select "重复字段"
 
  from table
 
  where "字段" = 'xx'
 
  group by "重复字段"having count(1) > 1 );
 
  删除
 
  delete from table
 
  where "字段" = 'xx'
 
  and id not in (select a.* from
 
  (select min(id)
 
  mysql 取出重复数据_MySQL 处理重复数据_处理数据库中重复数据
 
  from table
 
  where "字段" = 'xx'
 
  group by 重复字段 having count(1) > 1 ) a )
 
  and "重复字段" in (select b.* from
 
  (select "重复字段"
 
  from table
 
  where "字段" = 'xx'
 
  group by "重复字段"having count(1) > 1 ) b);
 
  所有字段重复时:使用 distinct
 
  insert into table1 select distinct * from table ;
 
  ALTER TABLE table RENAME TO table_20220908;
 
  ALTER TABLE table1RENAME TO table .
 

(编辑:百客网 - 域百科网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!