troubleshooting Question

SQL Delete Query

Avatar of Marcos27
Marcos27Flag for United States of America asked on
DatabasesMicrosoft SQL Server 2008SQL
2 Comments1 Solution40 ViewsLast Modified:
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
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros