读书人

为什么这个删除重复记录的语句不能执行

发布时间: 2012-02-12 17:16:33 作者: rapoo

为什么这个删除重复记录的语句不能执行,不能使用另名吗?
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)

读书人网 >SQL Server

热点推荐