Link to home
Start Free TrialLog in
Avatar of Marcos27
Marcos27Flag for United States of America

asked on

SQL Delete Query

Hello Experts -

Very simple question. I want to delete records from my Subtask table, but only records from a certain product line, which is recorded in a related Incident table. A record from the Incident table may or may not have an associated record from the Subtask table, and it could have several. The tables are linked by common ID, as noted in the query below.

Here is my select statement:

SELECT  *
      FROM Subtasks
      Join Incident on Subtasks.StandardLongInteger001=Incident.IncidentID
      And Incident.StandardText002 not in ('Product1', 'Product2', 'Product3')

Will the following delete statement work?

DELETE Subtasks
WHERE Exists
(
FROM Subtasks
      Join Incident on Subtasks.StandardLongInteger001=Incident.IncidentID
      And Incident.StandardText002 not in ('Product1', 'Product2', 'Product3')
)

If this is not correct, please point me in the right direction? Thank you!

- Mark
ASKER CERTIFIED SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the grade.  Good luck with your project. -Jim

btw, in case it helps, check out an article I wrote on SQL Server Delete Duplicate Rows