Discussion Locked

Using Criteria to Del Dup Val in a Fld?

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I need a way to delete output records from a query based on duplicate fields. Is there a string that I can use in the criteria that will filter out duplicates. To complicate matters, some of the values in the field are null and those must remain in the output.

I have tried First as a total, setting the property for the Query as UniqueValue and I have also tried UniqueRecord.

4 replies

by ben

Do you mean delete, or just filter out the duplicates? If you are trying to create a view that shows only records for which the said field is null, or is unique, then one could specify (I assume you're using native Access/Jet tables) a calculated field in the form of DCount("[field]","[table]","[field]"=[field]) an specify that the criteria is =1, then an or line for the field specifying is null. That way you get only records which have a value of the field that occurs once, or is null. Thisis not a terribly elegant solution, but simple. You could alternatively use a first query that simply counts the instances of each field value in the database, then join this in the second query, using the counted field instead of the DCount, whichcan be SLOW if lots of records.

Does this help you do what you are trying to do?

I am assuming a lot in this answer, but if you clarify what exactly you want to do I'll try to help further.

Good Luck,

B.

by ben

Just read your question again, and thought of a different interpretation - if you want to list each unique value once, and include the nulls, then your problem may be that the distinct functions in SQL will look at the entire record for uniqueness.If you choose only the duplicate field in the select query, it will return only the unique values - that said if you're trying to to this where do the nulls come in? What information do you want that is associated with the duplicate fields in each case - do you want to replace the nulls with something? Nz(field,valueifnull) will do this, or iif(isnull(field),valueifnull,field) will have the same effect but allow a little more scope.

Let me know!

B.

This discussion is closed to new replies.