如何去掉表中某一列有重复的数据,只保留一条
creat table A
(
id int,
Name varchar(50)
)
insert into a 
select 1,'qw1'
union all select 2,'qw1'
union all select 3,'qw2'要变成
1  qw1
3  qw2
或是
2  qw1
3  qw2

解决方案 »

  1.   

    delete x from A as x where exists(
           Select * from A where name=x.name and ID>x.ID)
      

  2.   

    当使用 SELECT 语句时,您可能不想要返回重复信息。例如,STAFF 有一个其中多次列出了几个部门编号的 DEPT 列,以及一个其中多次列出了几个工作说明的 JOB 列。 要消除重复行,在 SELECT 子句上使用 DISTINCT 选项。例如,如果将 DISTINCT 插入该语句,则部门中的每项工作仅列出一次:      SELECT DISTINCT DEPT, JOB
            FROM STAFF
            WHERE DEPT < 30
            ORDER BY DEPT, JOB此语句产生下列结果:      DEPT   JOB
         ------ -----
             10 Mgr
             15 Clerk
             15 Mgr
             15 Sales
             20 Clerk
             20 Mgr
             20 SalesDISTINCT 已消除了在 SELECT 语句中指定的一组列中所有包含重复数据的行。 
      

  3.   

    to 
    WangZWang(先来) ( ) 信誉:100 
    delete x from A as x where exists(
           Select * from A where name=x.name and ID>x.ID)编译错误
    请对你的回答负责一点
      

  4.   

    delete x from A as x where exists(
           Select * from A where name=x.name and ID>x.ID)
    --经测试是正确的,你哪儿有编译错误?
      

  5.   

    SET ROWCOUNT 1  
    delete from A
    WHERE 条件
      

  6.   

    to   WangZWang(先来) ( ) 信誉:100    Blog 
    对不起,我不小心输了个',',分已给你了,