Delete Records in Table A that Match Records in Table B?

foxhound

Board Regular
Joined
Mar 21, 2003
Messages
182
I have two tables: Hours History and Hours Adjustments. Both have the same fields: EmpNo, EmpName, DBA, NumHrs, and Date. Is there a way to have a record deleted from Hours History if it matches identically to a record in Hours Adjustment? I do not want to delete the record in Hours Adjustment, only in Hours History.

Thanks in advance for any assistance you can offer :)

Foxhound
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Join every field

Have you tried joining every field from both tables, and selecting * from the Hours History Table?


DELETE DISTINCTROW [Hours History].*
FROM [Hours History] INNER JOIN [Hours Adjustments] ON ([Hours History].Date = [Hours Adjustments].Date) AND ([Hours History].NumHours = [Hours Adjustments].NumHours) AND ([Hours History].DBA = [Hours Adjustments].DBA) AND ([Hours History].EmpName = [Hours Adjustments].EmpName) AND ([Hours History].EmpNo = [Hours Adjustments].EmpNo);

This will select all of the records that are identical from both tables, and delete them from the Hours History Table. (An importaint option is the DISTICTROW option, which is found by going to the query properties, and setting the "Unique Records" Property to YES.

Good luck.
 
Upvote 0

Forum statistics

Threads
1,221,519
Messages
6,160,293
Members
451,636
Latest member
ddweller151

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top