Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with this scenario

Status
Not open for further replies.
Mar 6, 2008
56
US
Hi guys,

Need help with writing the query with this scenario:

myTable:
---------------------------
ID Name status
---------------------------
1 Name1 good
2 Name2 bad
...
3 Name1 Bad
4 Name1 worst
-----------------------------
If a Name with status = good has been found and if there is another record on the same Name then those records need be deleted including itself.

In the above the records with Name1 needs to be deleted as it appeared again after having status = good

Thanks!
 
Code:
DELETE a
FROM myTable a
INNER JOIN
     (SELECT * FROM myTable b
      WHERE [status] = 'good') c
ON a.[Name] = c.[Name]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top