In MS Access 2016 I want to run a query that is synonymous with the Excel ‘Remove Duplicates’ function.
The excel query will remove duplicates and always leave one record.
For example, if we have 4 records where Specimen = BB000127 AND ADDON = NO (last column below) and we specify the Remove Duplicate query for Specimen and ADDON columns ,
the excel Remove Duplicate Function always returns at least one record:
when I run SQL query below in MS Access 2016 it remove’s ALL records where duplicates are found:
SELECT
ReportX.[Specimen], ReportX.[ADDON], ReportX.[Dept], ReportX.[Location], ReportX.[MRN],
ReportX.[Solcited_Status], ReportX.[FillerOrderNumber], ReportX.[PlaceGroupNumber], ReportX.[OrderType],
ReportX.[Investigation], ReportX.[Rejected], ReportX.[Mis_Un_labelled], ReportX.[No_samp_recd],
ReportX.[Amendedreport], ReportX.[OrderedBy], ReportX.[RespClinican], ReportX.[Collecteddate],
ReportX.[CollecteddateTime], ReportX.[messagedat]
FROM
ReportX
WHERE
ReportX.[Specimen] NOT IN (
SELECT
[Specimen]
FROM
[ReportX] AS Tmp
GROUP BY
[Specimen], [ADDON]
HAVING
Count(*) >= 1
AND
[ADDON] = [ReportX].[ADDON]
)
ORDER BY
ReportX.[Specimen], ReportX.[ADDON];
How can I modify the above query to return at least one record where a duplicate/duplicates exist?