如何在 SQL Server 中使用 INNER JOIN 进行删除?

我想在 SQL Server 2008 中使用 INNER JOIN 来删除.

I want to delete using INNER JOIN in SQL Server 2008.

但我收到此错误:

消息 156,级别 15,状态 1,第 15 行
关键字INNER"附近的不正确语法.

Msg 156, Level 15, State 1, Line 15
Incorrect syntax near the keyword 'INNER'.

我的代码:

DELETE 
FROM WorkRecord2 
INNER JOIN Employee 
        ON EmployeeRun=EmployeeNo
WHERE Company = '1' 
    AND Date = '2013-05-06'

推荐答案

您需要指定要从哪个表中删除.这是一个带有别名的版本:

You need to specify what table you are deleting from. Here is a version with an alias:

DELETE w
FROM WorkRecord2 w
INNER JOIN Employee e
  ON EmployeeRun=EmployeeNo
WHERE Company = '1' AND Date = '2013-05-06'

相关文章