Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

remove all but ONE duplicate entry

Posted on 2003-11-07
4
Medium Priority
?
574 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 1000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Suggested Courses

927 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