Solved

remove all but ONE duplicate entry

Posted on 2003-11-07
4
566 Views
Last Modified: 2012-05-04
by default if you run an unmatched query eg " table" against "find duplicates for table" it removes all the duplicate entries, effectively removing some rows with data that i want.  I would like to be able to keep only one of the duplicate entries in the finished list.

from this:

name1 phone1
name2 phone2
name2 phone2
name3 phone3

to this:

name1 phone1
name2 phone2
name3 phone3

NOT this:(which the unmatched query i spoke of results in)

name1 phone1
name3 phone3

any ideas?
0
Comment
Question by:NDSgroup
  • 2
4 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 9700426
To do this you employ a trick.

Create a copy of the table structure (not the data); make sure that the fields that identify duplicates are all part of a unique index.
Run an append query which appends all records from your old table to your new table.
Delete your old table and rename the new one.

(To copy a table structure, right-click the table name in the databse window, and copy and paste to a new named table)

Pete
0
 

Expert Comment

by:senan072100
ID: 9701480
if I understand you well, what about adding select distinct to the first query, by thoing this u will get ride of douplicated records, then run the output against the unmatched query, just an idea ???!!!
0
 
LVL 77

Expert Comment

by:peter57r
ID: 9701744
If your problem is that you have records which are complete duplicates (every field is the same) then you can use select distnct * to select records  Distinct looks at every selected field in your select statement.  You could use this as the basis of a make table or append query.

I did not anticipate this being the problem.  Most issues of this type are 'duplicate key' problems.

But if you have complete duplicates then there can't be a field to match on with your original table, since by definition this would mean that the records were not duplicates.  

Pete



0
 
LVL 1

Accepted Solution

by:
paul_st earned 250 total points
ID: 9705727
In order to do what your asking, your table will need to have a primary key, for example in your table you would have three fields (ID, Name, Phone) where ID is the primary key, ID could be an autonumber field. You could then execute the following SQL statement to remove the duplicate (name, phone) tuples:

DELETE * FROM Table1
WHERE ID IN
(SELECT DISTINCT A.ID FROM Table1 AS A, Table1 AS B
WHERE A.Name=B.Name AND A.Phone=B.Phone AND A.ID<B.ID)

Executing the query will keep the record with the greatest ID and delete all the others. For example if you had
1 Name1 Phone1
2 Name1 Phone1
3 Name1 Phone1

The following records would be deleted:
1 Name1 Phone1
2 Name1 Phone1

Leaving you with:
3 Name1 Phone1
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
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.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now