September 24, 2019 at 6:02 pm
Hi Folks:
Need help with query. I have process which runs daily. We have these 2 tables TABLE-A and TABLE-B. We would like to get records from TABLE-A deleted whenever the DeleteDate in TABLE-B is equal to Date in TABLE-A.
Thanks!
September 24, 2019 at 6:17 pm
This seems fairly straightforward. What have you tried and where are you running into problems?
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
September 24, 2019 at 6:20 pm
DELETE FROM TableA
WHERE EXISTS (SELECT 1
FROM TableB
WHERE TableB.DeleteDate = TableA.RecDate);
?
I guess I should have asked what you tried.
September 24, 2019 at 10:51 pm
Considering the content of the delete table, I'm thinking that you also need to include the ID in the delete criteria.
--Jeff Moden
Change is inevitable... Change for the better is not.
September 24, 2019 at 11:27 pm
As per Jeff's comment:As per Jeff's comment:
DELETE FROM TableA
WHERE EXISTS (SELECT 1
FROM TableB
WHERE TableB.DeleteDate = TableA.RecDate and TableB.ID = TableA.ID);
Because of duplicates in TableA on ID and RecDate, the delete will delete more (12) records from TableA.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply