select identity(int,1,1) as id,* into #temp from tabel
select * from  #temp where id in (
  select max(id) from #emp where having count(*)>1 group by col1,col2,col3...)

解决方案 »

  1.   

    如果member表只有username重复,而其它的都不重复,那怎么知道你要删除的是那一条记录呢?
        你可以这样,选择你要的那条记录,把他保存到新表,然后再删除旧表。
      

  2.   

    delete from member where id =)select top 1 id from member where username in(select username from member group by username having count(*)>1) order by username)多执行几次,没有影响的行就完成了
      

  3.   

    delete from member where username not in(selectselect distinct username from member)
      

  4.   

    delete t from table t, table t1 where t.username = t1.username and t.id > t1.id此语句将删除重复的行,只留下重复的username行中ID号最小的那一行,其中ID为表中任意无重复的列
      

  5.   

    select * from member group by username
      

  6.   

    你是想删除重复的行,还是只流一行?
    1:delete from member where username not in(selectselect distinct username from member)
    2:delete from member where username not in(selectselect top 1 username from member ) 
     
      
      

  7.   

    我刚好碰到一个和楼主一样的问题,已搞定:
    1.以这个表A生成另一个完全一样的表B.
    2.delete a
    3.insert into a (select max(col001) as col001,max(col002) as col002,.....from b group by username)
    4.删掉b
      

  8.   

    如果有ID字段,就是具有唯一性的字段delect table where id not in (  select max(id) from table group by col1,col2,col3...
    )
    group by 子句后跟的字段就是你用来判断重复的条件,如只有col1,那么只要col1字段内容相同即表示记录相同。2,如果是判断所有字段也可以这样
      select * into #aa from table group by id1,id2,....
      delete table 
      insert into table 
      select * from #aa3,没有ID的情况select identity(int,1,1) as id,* into #temp from tabel
    delect # where id not in (
      select max(id) from # group by col1,col2,col3...)
    delect table
    inset into table(...)
       select ..... from #temp
    col1+','+col2+','...col5 联合主键
    select * from  table where col1+','+col2+','...col5 in (  select max(col1+','+col2+','...col5) from table 
    where having count(*)>1
    group by col1,col2,col3,col4 
    )
    group by 子句后跟的字段就是你用来判断重复的条件,如只有col1,那么只要col1字段内容相同即表示记录相同。2,
    select identity(int,1,1) as id,* into #temp from tabel
    select * from  #temp where id in (
      select max(id) from #emp where having count(*)>1 group by col1,col2,col3...)
      

  9.   

    username字段重复的记录,其它字段内容有不同的,你要先确定你的取舍条件,否则,盲目地删除记录,可能会造成损失。
      

  10.   

    --表中有没有主键,如果有主键,就用:delete 表
    from 表 a where 主键<>(select top 1 主键 where username=a.username)
      

  11.   

    --如果表中没有主键,就增加一个标识字段.再处理
    --1.先增加标识字段
    alter table 表 add id int identity(1,1)
    go--再删除
    delete 表
    from 表 a where id<>(select top 1 id where username=a.username)
    go--处理完成后删除标识字段
    alter table 表 drop column id
      

  12.   

    --第一种方法写少了表名,表中有没有主键,如果有主键,就用:delete 表
    from 表 a where 主键<>(select top 1 主键 from 表 where username=a.username)
      

  13.   

    --例子(表中有主键的情况):
    create table 表(主键 int primary key,username varchar(10),info varchar(10))
    insert into 表
    select 1,'张三','a'
    union all select 2,'张三','b'
    union all select 3,'张三','c'
    union all select 4,'李四','d'
    union all select 5,'张三','e'
    union all select 6,'李四','f'
    go--删除处理
    delete 表
    from 表 a where 主键<>(select top 1 主键 from 表 where username=a.username)
    go--显示处理结果
    select * from 表
    go--删除测试环境
    drop table 表/*--测试结果
    主键          username   info       
    ----------- ---------- ---------- 
    1           张三         a
    4           李四         d(所影响的行数为 2 行)
    --*/
      

  14.   

    --如果表中没有主键,就增加一个标识字段.再处理(上面也写少了表名)--1.先增加标识字段
    alter table 表 add id int identity(1,1)
    go--再删除
    delete 表
    from 表 a where id<>(select top 1 id from 表 where username=a.username)
    go--处理完成后删除标识字段
    alter table 表 drop column id