表A:如下   
ID      aID      LH              MC
1 9366  5B(1.5m)配布 配布
2 9366  5B(1.5m)主布 主布
3 9366  5BT宝塔线 宝塔线
4 9366  5BT宝塔线 宝塔线
5 9366  5B沿条 沿条
6 9367  5B沿条 沿条
.....
=========================================
需要删除 aID=9366中 第4条冗余数据。
方法A:delete from 表A  a 
where aID=9366 (a.LH,a.MC) in (select LH,MC from 表A where aID=9366 group by LH,MC having count(*) > 1 ) 
and ID not in (select min(ID) from 表A  where aID=9366 group by LH,MC having count(*)>1) 一直提示什么
服务器: 消息 170,级别 15,状态 1,行 1
第 1 行: 'a' 附近有语法错误。
服务器: 消息 156,级别 15,状态 1,行 3
在关键字 'and' 附近有语法错误。
==============
方法B:
    delete   表A  from     表A  as T    where
  exists( select 1  from 表A    where   LH=T.LH   and   MC=T.MC  and  id < T.id  )
    and aID=9366
服务器: 消息 170,级别 15,状态 1,行 2
第 2 行: ' ' 附近有语法错误。
服务器: 消息 170,级别 15,状态 1,行 2
第 2 行: ' ' 附近有语法错误。

解决方案 »

  1.   

    delete 表A from 表A as T WHERE EXISTS(select 1 from 表A where LH=T.LH and MC=T.MC and id < T.id )  and aID=9366方法2 里面肯定有空格,你用这个试试
      

  2.   

    delete from 表A a  
     where aID=9366应该是a.id  (a.LH,a.MC) SQLServer不能这样,多字段要用exists,in (select LH,MC from 表A where aID=9366 group by LH,MC having count(*) > 1 )  
     and ID not in (select min(ID) 这里价格别名 from 表A where aID=9366 group by LH,MC having count(*)>1)
      

  3.   

    方法A:delete from 表A a  
    where aID=9366 and exists (select LH,MC from 表A where aID=9366 group by LH,MC having count(*) > 1 )  
    and ID not in (select min(ID) from 表A where aID=9366 group by aID,LH,MC )  方法B:--可能是输入法全角半角原因导致的,你再试试
    delete 表A from 表A as T where exists(select 1 from 表A where LH=T.LH and MC=T.MC and id<T.id) and aID=9366
      

  4.   

    顶楼上
    如何删除 SQL Server 表中的重复行http://blog.csdn.net/yangsh0722/article/details/8021246