I want to delete using INNER JOIN
in SQL Server 2008.
But I get this error:
Msg 156, Level 15, State 1, Line 15
Incorrect syntax near the keyword 'INNER'.
My code:
DELETE FROM WorkRecord2
INNER JOIN Employee ON EmployeeRun=EmployeeNo
WHERE Company = '1' AND Date = '2013-05-06'
Here's what I currently use for deleting or even, updating:
Try this, it might help
This version should works
You don't specify the tables for
Company
andDate
, you might want to fix that.Standard SQL using
MERGE
:The answer from @Devart is also Standard SQL though incomplete, should look more like this:
The important thing to note about the above is it is clear the delete is targeting a single table, as enforced in the second example by requiring a scalar subquery.
For me the various proprietary syntax answers are harder to read and understand. I guess the mindset for is best described in the answer by @frans eilering i.e. the person writing the code doesn't necessarily care about the person who will read and maintain the code.
Another way using
CTE
.Note : We cannot use
JOIN
insideCTE
when you want todelete
.Possible this be helpful for you -
Or try this -