sql语句删除数据表重复字段的方法

大家都可能遇到字段重复的情况,网上很多人在找方法,也给出了一些方法,但是有的方法是误导大家,铁牛写出以下方法,方便大家使用

  1.通过group by把重复的字段筛选出来,并建立临时表tmp

1
create table tmp as select max(id) as col1 from www group by dfdfd;

  2.从去重表对象里通过not in的条件来筛选出不在临时表的列col1,执行not in的删除操作

1
delete from www where id not in (select col1 from tmp);

  3.删除临时表

  1
drop table tmp;
原文地址:https://www.cnblogs.com/xlz307/p/4315778.html