Working on identifying duplicate vendor payments using SQL in MS Access. The business logic uses four column; Vendor #, Invoice #, Invoice Date and Invoice Amount. There are 5 core reviews, if all are the Exact matches (EEEE) or if at least one field is different (DEEE,EDEE,EEDE,EEED). I have it working for all 5, however its slow and I would like to improve on the code itself. I put an example of EEEE and DEEE below. Thoughts on a better way to write it?
Table SCHEMA:
ID - AutoNumber
VendorCol - Short Text
- VendorNameCol - Short Text
- InvoiceNoCol - Short Text
- InvAmountCol - Number
- InvoiceDateCol - Date/Time
EEEE:
SELECT *
FROM [Payment History] AS PH1
WHERE Exists
(Select *
From [Payment History] AS PH2
Where PH2.[ID] <>PH1.[ID]
AND PH2.[VendorCol] = PH1.[VendorCol]
AND PH2.[InvoiceNoCol] = PH1.[InvoiceNoCol]
AND PH2.[InvoiceDateCol] = PH1.[InvoiceDateCol]
AND PH2.[InvAmountCol] = PH1.[InvAmountCol])
ORDER BY [InvAmountCol] DESC , [InvoiceDateCol] DESC;
Example of desired result: EEEE Example
DEEE: Different vendor # but all else equal
SELECT *
FROM [Payment History] AS PH1
WHERE Exists
(Select *
From [Payment History] AS PH2
Where PH2.[ID] <>PH1.[ID]
AND PH2.[VendorCol] <> PH1.[VendorCol]
AND PH2.[InvoiceNoCol] = PH1.[InvoiceNoCol]
AND PH2.[InvoiceDateCol] = PH1.[InvoiceDateCol]
AND PH2.[InvAmountCol] = PH1.[InvAmountCol])
ORDER BY [InvAmountCol] DESC , [InvoiceDateCol] DESC;
Example of desired result: DEEE Example
I can post the other ones, but figured this would get most there.