比如一张表
有以下数据 
字段1  字段2  字段3  字段4 字段5 
1      2      3    4     5   
A      B      C    D     E
1      2      3    4     5 
A      B      C    D     E



其中  第一条 和 第三条 一样
      第二条 和 第四条 一样
怎么才能写SQL,删除其中重复的数据(可能还后很多这样的)
让最后是
字段1  字段2  字段3  字段4 字段5 
1      2      3    4     5   
A      B      C    D     E   

解决方案 »

  1.   

    你可以把数据库加一个识别的字段
    例如:加了一 varchar(1)字段,值就是0和1
    这样就可以写如下:delete from a where a.字段1 in ( 1 , A) and a. = 0然后再把字段中的值清空,在删除字段,这样就可以了。 
      

  2.   

    delete from test a where a.rowid = (select max(rowid) from test b where a.字段1 = b.字段1
    and a.字段2 = b.字段2 and a.字段3 = b.字段3 and a.字段4 = b.字段4 and a.字段5 = b.字段5)可以看看这个
      

  3.   

    提供一个源表数据量比较多的时候重复记录删除的方法。
    首先因为源表数据量,如果你想一步就搞定,你会等个半死,我的建议步骤如下:
    假定你想删除的表是Test,表中有field1,field2,...,feildn个字段.
    1.create table Test1 as 
            select field1,
                   field2,
                   ...,
                   feildn
              from Test
          group by field1,
                   field2,
                   ...,
                   feildn;
    2_1.truncate table Test;
       insert into Test1
            select field1,
                   field2,
                   ...,
                   feildn
              from Test1;
    或者
    2_2. drop table Test;
        rename Test to Test1;
      

  4.   

    http://blog.csdn.net/winson4282000/
    正好有你想要的文章
    哈哈,前天刚贴的