Solved

remove all but ONE duplicate entry

Posted on 2003-11-07
4
571 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
[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
  • 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

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…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

628 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