Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

remove all but ONE duplicate entry

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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…

730 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