Suppose I have a table named tbl_med, which has six fields: [nom_lab], [nom_desc], [nom_apres], [date_vig], [cod_med], [vr_pmc].
I want an MS Access SQL query that will:
- Find duplicated records in relation to four of the fields: [nom_lab], [nom_desc], [nom_apres], [date_vig].
- Show all six fields (not just the ones being used to check for duplicates).
I used the MS Access "Find Duplicates Query Wizard", which gave me the following SQL:
SELECT tbl_med.[nom_lab], tbl_med.[nom_desc], tbl_med.[nom_apres], tbl_med.[date_vig], tbl_med.[cod_med], tbl_med.[vr_pmc]
FROM tbl_med
WHERE tbl_med.[nom_lab]
IN
(
SELECT [nom_lab]
FROM [tbl_med] As Tmp
GROUP BY [nom_lab], [nom_desc], [nom_apres],[date_vig]
HAVING Count(*)>1
And [nom_desc] = [tbl_med].[nom_desc]
And [nom_apres] = [tbl_med].[nom_apres]
And [date_vig] = [tbl_med].[date_vig]
)
ORDER BY tbl_med.[nom_lab], tbl_med.[nom_desc], tbl_med.[nom_apres], tbl_med.[date_vig];
Could anyone explain why the three And
conditions between the horizontal rule lines above are necessary?
Does anyone have a more intuitive query which would be easier to understand?