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
Solved

Find duplicates by comparing 5 fields in a query

Posted on 2011-09-13
4
236 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…

809 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