Solved

Access 2007 - duplicates

Posted on 2011-02-20
8
843 Views
Last Modified: 2012-05-11
My OS is windows 7, I have the following SQL statement which pulls out all the duplicates.  How do I modify the code to only extract the unique records.  thank u
SELECT [Seniors Club].Email, [Seniors Club].[Last Name]
FROM [Seniors Club]
WHERE ((([Seniors Club].Email) In (SELECT [Email] FROM [Seniors Club] As Tmp GROUP BY [Email] HAVING Count(*)>1 )))
ORDER BY [Seniors Club].Email;

Open in new window

0
Comment
Question by:jegajothy
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 34937560
SELECT Distinct [Seniors Club].Email, [Seniors Club].[Last Name]     .......
0
 
LVL 26

Expert Comment

by:tigin44
ID: 34937616
this wil only list the unique records...
SELECT [Seniors Club].Email, [Seniors Club].[Last Name]
FROM [Seniors Club]
WHERE [Seniors Club].Email NOT IN (SELECT [Email] 
										FROM [Seniors Club] As Tmp 
										GROUP BY [Email] 
										HAVING Count(*)>1 )
ORDER BY [Seniors Club].Email;

Open in new window

0
 

Author Comment

by:jegajothy
ID: 34937779
in response to Peter57r, I ran your code, but the results are confusing.  
There are 112 records.  a straight query for duplicates reveals 7 duplicates.  But your code reveals 110 unit records.  I have Trimed the data inthe email field to eliminate the blank or leading spaces.
Hope u can throw some light. thank u
In response to Tigin44, your code did not produce any results, which means no Unique records.
Hope u can troubleshoot the code. thank u.
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 77

Expert Comment

by:peter57r
ID: 34938106
What is your duplicates test based on in your duplicates query?

Your question stated you wanted unique records, and that is what Distinct will produce, based on the value of BOTH selected fields (Email + LastName) .  
0
 
LVL 39

Accepted Solution

by:
als315 earned 500 total points
ID: 34938138
If you like to select unique Email only, you can group by email and select first of Last Name:
SELECT [Seniors Club].Email, First([Seniors Club].[Last Name]) AS LastName
FROM [Seniors Club]
GROUP BY [Seniors Club].Email;
0
 
LVL 39

Expert Comment

by:als315
ID: 34938237
If you are working with db from Question 26834411, you task is not so simple.
As I can see, one person may have different emails:
bavaniraj@verizon.net      V N Rajgopalan
bavaniraj@yahoo.com      Virinchipuram Rajgopalan

And different persons can have one email:
narendra03@aol.com      Chand Arora
narendra03@aol.com      Narendra Arora


What results are you expecting to get in this cases?
0
 
LVL 39

Expert Comment

by:als315
ID: 34938286
You also may need to prepare email field for compare:
trim(Replace(Replace(Nz([Seniors Club]![Email],""),"<",""),">",""))
0
 

Author Closing Comment

by:jegajothy
ID: 34938721
your syntax produced the right and expected results. thank u
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question