SQL语句去掉重复数据

有的时候会有部分字段重复,比如ID值不一样,但EMAIL一样,需要删除掉重复的数据,但相同数据只留一条的情况,如下:

1.先查询出重复的数据

select email

  from users u1

 where rowid <> (select max(rowid) from users u2 where u1.email = u2.email);

2.删除重复的数据

 delete from users u1 where rowid<>(select max(rowid) from users u2 where u1.email=u2.email);

猜你喜欢

转载自mukeliang.iteye.com/blog/2032355