使用连接时DELETE查询中的错误是什么

时间:2012-06-23 09:21:35

标签: sql-server sql-delete

在注释DELETE语句并尝试使用SELECT语句时,代码运行正常。 请帮忙

DELETE FROM 
--select * from 
Site as s
join 
(select SiteID,Code, Name, Dense_rank() over (partition by Code order by SiteID ) as Rank from Site
) as t 
on s.SiteID = t.SiteID
WHERE t.Rank != 1

获取以下错误消息

Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'as'.
Msg 156, Level 15, State 1, Line 8
Incorrect syntax near the keyword 'as'.

1 个答案:

答案 0 :(得分:5)

您不能为delete表添加别名,但delete可以引用别名。而不是:

delete from Site as s
...

尝试:

delete from s
from Site as s
...