473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Duplicate Records - Same Table - Multiple Criteria Fields - Please Help!

Any assistance is much appreciated...

I have a table with duplicate record information and I need to remove
certain records based on values in four different fields. For example:

PK field Name Date1 Date2 Date3
1 Bill 1/21/04 1/18/02 5/14/04
2 Bill 1/15/03 1/18/02 5/14/04
3 Bill 1/25/04 5/14/04

I want to compare the records and keep the record with the most recent
date in field Date3, if the dates match then I want to compare the
dates in field Date2 and if the records match there I want to compare
the dates in field Date1 and delete the one with the oldest dates.
Thanks.

Nov 13 '05 #1
2 4679
"zeke" <tu****@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Any assistance is much appreciated...

I have a table with duplicate record information and I need to remove
certain records based on values in four different fields. For example:

PK field Name Date1 Date2 Date3
1 Bill 1/21/04 1/18/02 5/14/04
2 Bill 1/15/03 1/18/02 5/14/04
3 Bill 1/25/04 5/14/04

I want to compare the records and keep the record with the most recent
date in field Date3, if the dates match then I want to compare the
dates in field Date2 and if the records match there I want to compare
the dates in field Date1 and delete the one with the oldest dates.
Thanks.

The action query works on the above table structure and data for a table
named Table1, and should do the trick:

DELETE T1.*
FROM Table1 AS T1
WHERE T1.[PK field] NOT IN
(SELECT TOP 1 T2.[PK field]
FROM Table1 AS T2
WHERE T2.Name=T1.Name
ORDER BY Date3 DESC, Date2 DESC, Date1 DESC;)
;

See if it works for you.
Nov 13 '05 #2
This is excellent. Works perfectly, and much simpler than the
direction I was heading. Thank you!

ByteMyzer wrote:
"zeke" <tu****@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Any assistance is much appreciated...

I have a table with duplicate record information and I need to remove certain records based on values in four different fields. For example:
PK field Name Date1 Date2 Date3
1 Bill 1/21/04 1/18/02 5/14/04
2 Bill 1/15/03 1/18/02 5/14/04
3 Bill 1/25/04 5/14/04

I want to compare the records and keep the record with the most recent date in field Date3, if the dates match then I want to compare the
dates in field Date2 and if the records match there I want to compare the dates in field Date1 and delete the one with the oldest dates.
Thanks.
The action query works on the above table structure and data for a

table named Table1, and should do the trick:

DELETE T1.*
FROM Table1 AS T1
WHERE T1.[PK field] NOT IN
(SELECT TOP 1 T2.[PK field]
FROM Table1 AS T2
WHERE T2.Name=T1.Name
ORDER BY Date3 DESC, Date2 DESC, Date1 DESC;)
;

See if it works for you.


Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Catherine Jo Morgan | last post by:
Can I set it up so that a certain combination of fields can't contain the same entries, on another record? e.g. a combination of FirstName/LastName/address? Or FirstName/LastName/phone? Or...
2
by: steevp | last post by:
Hi, Please excuse the newbie type question, but I am wracking my brains to solve what should be a simple query. I have three fields in a table F1, F2, F3. Any of the fields may contain...
4
by: HLCruz via AccessMonster.com | last post by:
I am working with a database that has client information separated in to 4 related tables - tFolder, tAddress, tEmail, tPhone number. In addition there are related tables tGifts and tCalls. The...
1
by: rgurganus | last post by:
I'm trying to setup a way to find possible duplicate or near-duplicate records of contact people. I have a table of 50k records doing an inner join with itself, something like this: SELECT...
3
by: sar68 | last post by:
I'm using Access 2007 on windows vista. Intel T7400 with 2.16 GHz and 2 gigs of ram. 64 bit os. If I run a query that goes across multiple tables, I get sensible results. However, if I run a...
11
by: shriil | last post by:
Hi I have this database that calculates and stores the incentive amount earned by employees of a particular department. Each record is entered by entering the Date, Shift (morn, eve, or night)...
6
by: Dave | last post by:
On my form I have combo boxes. These combo boxes, after updating them, populate respective listboxes that are located below the combo boxes on the same form. I am trying to use a "generate...
3
by: sierra7 | last post by:
I have found that I have duplicates in my Products table. I am using the DLookup() function to find a ProductID by a product 'criteria' and only create a new one if can not find a match e.g. ...
2
Zwoker
by: Zwoker | last post by:
Greetings everyone, I have a problem that I hope has a simple solution. I am using MS Access 2003. I have a table that is a list of financial transactions. I am using a make table query over...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.