日期:2014-05-18  浏览次数:20782 次

为什么这个删除重复记录的语句不能执行,不能使用另名吗?
delete   from  
from   osrd   a
where   a.myid   !=  
(select   max(myid)   from   osrd   b   where   b.ItemCode=a.ItemCode   and   b.DocType=a.DocType   and   b.DocEntry=a.DocEntry   and   b.DocLineNum=a.DocLineNum)

错误信息:
服务器:   消息   156,级别   15,状态   1,行   2
在关键字   'from '   附近有语法错误。


------解决方案--------------------
delete from osrd a
where a.myid !=
(select max(myid) from osrd b where b.ItemCode=a.ItemCode and b.DocType=a.DocType and b.DocEntry=a.DocEntry and b.DocLineNum=a.DocLineNum)
------解决方案--------------------
delete from
from osrd a

两个from ,笔误?
------解决方案--------------------
多了個from ,將前面的那個from改為a

------解决方案--------------------
用exists应该效率会好一点:
delete a from
from osrd a
where exists
(select max(myid) from osrd b where b.ItemCode=a.ItemCode and b.DocType=a.DocType and b.DocEntry=a.DocEntry and b.DocLineNum=a.DocLineNum and myid> a.myid)