mysql删除表中某一字段重复的记录

时间:2024-01-22 10:35:43 

比如,表:event(id int(10) auto_increment primary key,
                sid int(10)not null,
                detail text)

我想删除表event中sid重复的记录,请问有没有这样SQL语句?或是通过其它方法?


delete from event as e 
where id != (select min(id) from event where sid=e.sid); 


or 


delete from event 
where sid not in (select mid from (select sid ,min(id) as mid from event group by sid)) 


应该是有用的代码


alter ignore table event add unique index idu_sid (sid);
alter table event drop index idu_sid;

标签:mysql,重复记录
0
投稿

猜你喜欢

  • MySQL和Python交互的示例

    2024-01-18 07:02:11
  • MySQL 8.0新特性 — 管理端口的使用简介

    2024-01-28 21:53:46
  • 清除SQLServer日志的两种方法

    2024-01-18 15:34:13
  • Go语言map元素的删除和清空

    2024-02-05 10:42:25
  • Python必须了解的35个关键词

    2023-05-20 07:37:33
  • 一句Sql把纵向表转为横向表,并分别分组求平均和总平均值

    2024-01-22 19:30:37
  • Javascript中各种trim的实现详细解析

    2024-04-18 10:55:04
  • python的endswith()的使用方法及实例

    2023-04-30 04:42:11
  • Python使用pandas和xlsxwriter读写xlsx文件的方法示例

    2022-05-14 00:35:25
  • 如何利用触发器实现两个数据库间的同步

    2009-01-06 11:26:00
  • 启动Atom并运行python文件的步骤

    2023-12-22 02:26:11
  • python中对_init_的理解及实例解析

    2023-03-15 11:08:23
  • 学会sql数据库关系图(Petshop)

    2012-10-07 10:34:49
  • PHP的Yii框架中行为的定义与绑定方法讲解

    2023-07-21 20:42:33
  • python案例练习合集

    2021-03-04 15:30:27
  • python通过百度地图API获取某地址的经纬度详解

    2021-11-06 12:14:45
  • 带中英文翻译功能的收藏夹

    2008-07-31 11:33:00
  • javascript 跨浏览器的事件系统

    2010-07-28 19:34:00
  • python自动提取文本中的时间(包含中文日期)

    2023-08-22 21:32:11
  • Vue传参一箩筐(页面、组件)

    2024-05-29 22:44:13
  • asp之家 网络编程 m.aspxhome.com