45 pts.
 Access Query – Repeating fields
I have a file of 70K names. Some are dups. I want to create a indicator in Access to flag when the name is repeated indicate 'Y' else 'N'. Any ideas on how to create a query to do this

Software/Hardware used:
Microsoft Access 2003
ASKED: August 13, 2009  5:27 PM
UPDATED: August 17, 2009  3:42 AM

Answer Wiki:
This would give you a list of repeating names Select NameFld from YourFile Group by NameFld Having count(*) > 1 So you can update your file to put 'Y' s in it <pre>Update YourFile Set DupNameFld = 'Y' where NameFld in ( Select NameFld from YourFile Group by NameFld Having count(*) > 1 )</pre> and update your file to put 'N' s in it <pre>Update YourFile Set DupNameFld = 'N' where NameFld NOT in ( Select NameFld from YourFile Group by NameFld Having count(*) > 1 )</pre>
Last Wiki Answer Submitted:  August 13, 2009  9:18 pm  by  carlosdl   63,580 pts.
All Answer Wiki Contributors:  carlosdl   63,580 pts. , philpl1jb   44,630 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

You could avoid the subselect in the second update, assuming that DupNameFld is null for all records at the beginning…

Update YourFile
Set DupNameFld = ‘N’
when DupNameFld is null

 63,580 pts.

 

Or you could update all records to ‘N’ first, and then update the duplicated to ‘S’.

Update YourFile
Set DupNameFld = 'N'


Update YourFile
Set DupNameFld = 'Y'
when NameFld in
( Select NameFld from YourFile 
Group by NameFld
Having count(*) > 1 )
 63,580 pts.

 

Thanks for answering my question. I do have a follow up, I’m getting a syntax error with the code, so
I think I’m typing it wrong. To help clarify, the fieldname is ‘phyname’ and the file name is ‘HSD’.
I’m getting an error on the when, but I don’t know why. Thank you.

 45 pts.

 

That was a typo, it is not WHEN, but WHERE.

I modified the original answer from Philpl1jb.

Update YourFile
Set DupNameFld = ā€˜N’

Update YourFile
Set DupNameFld = ā€˜Y’
where NameFld in
( Select NameFld from YourFile
Group by NameFld
Having count(*) > 1 )

Please change the field and table names as needed.

 63,580 pts.

 

Thanks for the fix Carlos – WHERE not When — mind was somewhere else.

 44,630 pts.

 

Thanks for all your help. That worked!.

 45 pts.

 

All nice suggestions and comments.

Just wanted to mention that Access 2007 provides a Wizard (Query) to display Duplicate records. One can select the field for duplicate (Name in this case) along with other associated fields. This may be helpful to ascertain if the record is genuinely duplicate.

 2,510 pts.