Solved

Find duplicates by comparing 5 fields in a query

Posted on 2011-09-13
4
233 Views
Last Modified: 2012-05-12
Hi experts!  

I am working in Access 2010.

I have a query that has these fields: (please see screen shot).

The goal is to compare records in this query based on four fields and dump the duplicate record based on the value of a fifth field:

If ALL of the below four fields are identical....

[RequestDate]
[Company]
[Product]
[Quantity]

then....
the fifth field
[Source]
determines which record will be dropped and which record will stay of the duplicate records.

The [Source] field will always have one of two entries: Susie OR FMS.  FMS should be the winner in all duplicate records.

I hope there is a simple way to solve this!

Thank you.
Untitled.png
0
Comment
Question by:Sashaski
  • 2
  • 2
4 Comments
 
LVL 42

Expert Comment

by:dqmq
ID: 36532052
Delete * from yourtable T1
  where T1.Source <> "FMS"
  and exists
     (Select * from yourtable T2 where
             t1.RequestDate = t2.requestdate
       and t1.Company = t2.company
       and t1.Product = T2.product
       and t1.Quantity = T2.quantity
       and t2.Source = "FMS"
      )




Select ID from yourtable where source <> "FMS"
0
 
LVL 42

Accepted Solution

by:
dqmq earned 500 total points
ID: 36532061
pls ignore residual select at end of prev answer
0
 

Author Comment

by:Sashaski
ID: 36532236
Thank you dgmg...I tried the code above, it filtered my query to just show the "FMS" records.  I dropped the last select statement. so the code is:


Delete * from yourtable T1
  where T1.Source <> "FMS"
  and exists
     (Select * from yourtable T2 where
             t1.RequestDate = t2.requestdate
       and t1.Company = t2.company
       and t1.Product = T2.product
       and t1.Quantity = T2.quantity
       and t2.Source = "FMS"
      )
0
 

Author Comment

by:Sashaski
ID: 36532247
My bad, that worked! Thank you so much!

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

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

762 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

26 Experts available now in Live!

Get 1:1 Help Now