请参考这里
http://community.csdn.net/Expert/topic/4062/4062530.xml?temp=.2817194假设表中的数据如下:
#colPK# #colA# #colB#
1 2 3
2 2 3
3 3 3
4 3 3目的是删除后只留下如下的纪录:
#colPK# #colA# #colB#
1 2 3
3 3 3我们构造如下的数据:
create table dbo.testA
(colPK int,colA int, colB int)insert into testA values(1,2,3)
insert into testA values(2,2,3)
insert into testA values(3,3,3)
insert into testA values(4,3,3)第一种办法(比较笨的办法)
使用游标,找到重复的,删除,效率极低第二中办法(比第一种效率稍有提高,但我自己觉的还不是最好的办法)
首先,把重复记录插入一个临时表(重复的只插去一条)
select 0 as colPK,colA,colB into dbo.testB from testA group by colA,colB
这里以0为值构造了一个colPK列,以备更新
接下来,更新我们构造的临时表testB
update testB set colPK=a.colPK from testA as a,testB as b where a.colA=b.colA and a.colB=b.colB
这样就完成了!
小弟这里只是抛砖引玉!献丑!

解决方案 »

  1.   

    如果你的库中中文品牌和英文品牌两个字段本身是唯一对应的
    用  select distinct 中文品牌,英文品牌 from tb ; 就可以了
      

  2.   

    不明白,是要:
    select distinct 中文品牌,英文品牌 from 表?
      

  3.   

    楼主的意思就是查询出所有品牌啦
    用select distinct [中文品牌],[英文品牌] from 表 就可以拉