Solved

Access 2007 - duplicates

Posted on 2011-02-20
8
854 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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 40

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 40

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 40

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
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 start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

733 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