View Full Version : Delete Duplicates redux...


sbrooks
04-03-2002, 07:40 AM
I know this issue has been addressed several times on this board, but I believe I have a little more complicated scenario. I want to be able to delete records based on duplication of 4 fields, but on top of that I want it to query FieldX and only delete duplicates where FieldX is null. I've tried implementing the following SQL code which is a modified Find Duplicates Query, to no avail:

SELECT tblName.Field1, tblName.[Field2], tblName.[Field3], tblName.[FieldX] FROM tblName WHERE (((tblName.Field1) In (SELECT [Field1] FROM [tblName] As Tmp GROUP BY [Field1],[Field2],[Field3] HAVING Count([tblName].[Field1])>1 And [Field2Name] = [tblName].[Field2] And [Field3Name] = [tblName].[Field3]))) AND (((tblName.FieldX) Is Null));

The problem is, while this will do away with dupes that are NULL in FieldX, it doesn't help with dupes that are BOTH null; I DO want at least one of them. Anyone have any further suggestions, I'm at my wit's end?
TIA

S. Brooks

RV
04-03-2002, 09:29 PM
>The problem is, while this will do away with dupes that are NULL in FieldX, it doesn't help with dupes that are BOTH null; I DO want at least one of them.<

Can you be more specific in what you try to do?
What do you mean by "dupes that are both NULL in FieldX", there's only one field FieldX...

If your fields Field1, Field2, Field3 and FieldX contains the following data, what would be the result you're looking for:

Field1 Field2 Field3 FieldX
1 2 3 4
1 2 3 4
1 2 3
1 3 4
1 3 4 2
1 2 5 1

RV