蚂蚁的:去除重复值如果有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...)  
 
Top 
 
 回复人: zzjzhao(风云) ( ) 信誉:100  2003-9-5 8:13:25  得分:10 
 
 
  
楼上回答的很全面了  
 
Top 
 
 回复人: pengdali(大力 V2.0) ( ) 信誉:534  2003-9-5 8:19:54  得分:0 
 
 
  
删除重复的,只留一条:alter table 表 add  newfield int identity(1,1)delete 表
where newfield not in(
 select min(newfield) from 表 group by 除newfield外的所有字段
                     )alter table 表 drop column newfield  
 
Top 
 
 回复人: yujohny(踏网无痕) ( ) 信誉:100  2003-9-5 8:20:04  得分:10 
 
 
  
这个问题,肯定有很多人问过,也很多人答过了  
 
Top 
 
 回复人: pengdali(大力 V2.0) ( ) 信誉:534  2003-9-5 8:21:58  得分:20 
 
 
  
或:
select distinct * into #temp from 表
truncate table 表
insert 表 select * from #temp
drop table #temp  
 
Top 
 
 回复人: nboys() ( ) 信誉:100  2003-9-5 8:23:47  得分:10 
 
 
  
select distinct * into #temp from tableNametruncate table tableNameinsert into tableName select * from #tempdrop table #temp
  
 
Top 
 
 回复人: fmdsaco(老小不大) ( ) 信誉:100  2003-9-5 9:30:12  得分:10 
 
 
  
use 数据库
alter table 表 add rownum int identity(1,1)
go
delete from 表 where rownum not in (select min(rownum ) from 表group by 重复字段名)
go
alter table 表 drop column rownum
go  
 
Top 
 
 回复人: lusee() ( ) 信誉:100  2003-9-5 11:17:44  得分:0 
 
 
  
谢谢各位的帮助!问题解决了!  
 
Top 
 
 该问题已经结贴 ,得分记录: JGTM2000 (10)、 txlicenhe (30)、 zzjzhao (10)、 yujohny (10)、 pengdali (20)、 nboys (10)、 fmdsaco (10)、  
 
 
 
 
    
 
 
 管理 | 关闭窗口  
 

解决方案 »

  1.   

    蚂蚁的:去除重复值
    如果有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...)
      

  2.   

    http://expert.csdn.net/Expert/topic/2225/2225703.xml?temp=.8066675
      

  3.   

    删除重复的,只留一条:alter table 表 add  newfield int identity(1,1)delete 表
    where newfield not in(
     select min(newfield) from 表 group by equip_name,equip_status
                         )alter table 表 drop column newfield