07-31-2023, 09:36 AM
You don't specify the tables for `Company` and `Date`, and you might want to fix that.
Standard SQL using `MERGE`:
MERGE WorkRecord2 T
USING Employee S
ON T.EmployeeRun = S.EmployeeNo
AND Company = '1'
AND Date = '2013-05-06'
WHEN MATCHED THEN DELETE;
[The answer from Devart][1] is also *standard* SQL, though incomplete. It should look more like this:
DELETE
FROM WorkRecord2
WHERE EXISTS ( SELECT *
FROM Employee S
WHERE S.EmployeeNo = WorkRecord2.EmployeeRun
AND Company = '1'
AND Date = '2013-05-06' );
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][2], i.e. the person writing the code doesn't necessarily care about the person who will read and maintain the code.
[1]:
Standard SQL using `MERGE`:
MERGE WorkRecord2 T
USING Employee S
ON T.EmployeeRun = S.EmployeeNo
AND Company = '1'
AND Date = '2013-05-06'
WHEN MATCHED THEN DELETE;
[The answer from Devart][1] is also *standard* SQL, though incomplete. It should look more like this:
DELETE
FROM WorkRecord2
WHERE EXISTS ( SELECT *
FROM Employee S
WHERE S.EmployeeNo = WorkRecord2.EmployeeRun
AND Company = '1'
AND Date = '2013-05-06' );
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][2], i.e. the person writing the code doesn't necessarily care about the person who will read and maintain the code.
[1]:
[To see links please register here]
[2]:[To see links please register here]