Solved

SQL delete query for duplicate records in Access

Posted on 2008-10-31
9
1,281 Views
Last Modified: 2012-05-05
This is a follow up question to an earlier question.  I have an Access database with duplicate records.  The key is a composite of FUND, GROUP, ID.  How would I write a query to delete duplicate records in the table.
0
Comment
Question by:VBStudent
[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
  • 2
  • 2
  • +2
9 Comments
 
LVL 12

Expert Comment

by:jazzIIIlove
ID: 22852809
Hi there;

DELETE FROM our_table WHERE rowid not in(SELECT MIN(rowid) FROM our_tabl eGROUP BY column1, column2, column3... ;

Here column1, column2, column3 constitute the identifying key for each record.

Best regards...
0
 

Author Comment

by:VBStudent
ID: 22853306
it doesn't appear as though rowid is recognized in Access.  Any other suggestions?
0
 
LVL 7

Expert Comment

by:UniqueData
ID: 22853830
don't award any points to me, just thought I would help out...

rowid is probably referring to a unique record id, usually an AutoNumber field.  I know you have the three fields that make up the key, but do you also have (or can you add) an AutoNumber?

Michael
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 9

Expert Comment

by:jamesgu
ID: 22855495
delete from <table>
inner join ( select FUND, GROUP, ID from <table> group by FUND, GROUP, ID having count(*) > 1) b on
<table>.FUND = a.FUND
<table>.GROUP = GROUP
<table>.ID = a.ID



0
 
LVL 9

Accepted Solution

by:
jamesgu earned 500 total points
ID: 22855516
delete from <table>
from <table>
inner join ( select FUND, GROUP, ID from <table> group by FUND, GROUP, ID having count(*) > 1) b on
<table>.FUND = a.FUND
<table>.GROUP = GROUP
<table>.ID = a.ID

--missed a from clause
0
 
LVL 12

Expert Comment

by:jazzIIIlove
ID: 22856258
yes...rowId is autoNumbered field of yours...
0
 

Author Closing Comment

by:VBStudent
ID: 31512146
Thank you for your help
0
 

Expert Comment

by:sarcharan
ID: 23681243
I thank all of you for helping me. I found one more document to be quite interesting.

delete from t1 where tl.rowid >(select min(tl2.rowID) from t1 tl2 where tl.col1 = tl2.col1 and tl.col2 = tl2.col2)
====================
sp_rename 'dup_authors', 'temp_dup_authors'

select distinct *
into dup_authors
from temp_dup_authors

drop table temp_dup_authors
Deleting-Duplicate-Records.doc
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
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…

726 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