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:

      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
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornSQL Server Data DudeCommented:
< Knee-jerk reaction.  Deletes can have JOINs.  HOLY GOD MAKE A BACKUP BEFORE EXECUTING THIS >

FROM Subtasks s
   JOIN Incident i on s.StandardLongInteger001=i.IncidentID
      And i.StandardText002 not in ('Product1', 'Product2', 'Product3')

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jim HornSQL Server Data DudeCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.