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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL query to Delete row if corresponding query is true

Status
Not open for further replies.

AccessHelp123

Programmer
Apr 27, 2005
91
US
Hi,

I am trying to create a queries which deletes certain rows depending on another query.


SELECT *
FROM tableTemp
WHERE networkCC = 1 AND cellIdentity In (SELECT [Cell ID] FROM tableSiteStatus WHERE [Final Cut-Over Date]="Yes");


I need to delete values that have a networkCC = 0 if there exists a corresponding networkCC = 1 from the above query.
Can someone please help me with this. Appreciate it.

 
Something like this ?
DELETE FROM tableTemp D
WHERE networkCC = 0 AND EXISTS (
SELECT * FROM tableTemp T INNER JOIN tableSiteStatus S ON T.cellIdentity = S.[Cell ID]
WHERE T.networkCC = 1 AND S.[Final Cut-Over Date]="Yes" AND T.cellIdentity = D.cellIdentity
);

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top