473,385 Members | 1,798 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,385 software developers and data experts.

Help removing duplicates which have oldest date.

1
Hi guys.

I have a database of phone numbers and names and things. Each sheet is holding between 500k and 2 million records.

Each record has a date which it was called. Sometimes the same number is in the database up to 10 times, each with a different date that it was called.

What I need is to keep ONLY the latest record of the number being called.

So;
eg.

Number: 03 1234 1234 Called on: 13/06/08
Number: 03 1234 1234 Called on: 01/01/07
Number: 03 1234 1234 Called on 03/06/05

I want to delete all but the one that was called on 13/06/08.

If anyone can provide some insight, it would be greatly appreciated. Thanks - Kat.
Jun 26 '08 #1
2 6113
Stewart Ross
2,545 Expert Mod 2GB
Hi. One way to do what you want is to use a Make Table query to copy the latest records into a new table. That way you can either (a) retain the original table for reference purposes, or (b) delete it after making the new table.

The SQL for the make table query is along the lines of
Expand|Select|Wrap|Line Numbers
  1. SELECT [phonetable].[phonenumber], max([datelastcalled]) as LastCallDate
  2. INTO [newtablename]
  3. FROM [phonetable]
  4. GROUP BY [phonetable].[phonenumber]
Why copy to a separate table? Because the SELECT above will only return one record per phone number per date, which a direct deletion cannot guarantee to do in the circumstances you have told us.

Given the information available it is at least not impossible in your original table that there may be more than one record for any one call date. In turn there could be more than one call record for the most recent call date. Directly deleting rows less than the most recent call date would not affect these duplicates, and dealing with them would entail a second pass. Copying to a new table provides a 'clean' copy of the most recently-dated records only and removes all duplicates in one operation.

-Stewart
Jun 26 '08 #2
NeoPa
32,556 Expert Mod 16PB
I usually use an UPDATE / DELETE process when doing something like this. It does rely on having a spare field available as a simple Delete flag. It is also not the most efficient process when dealing with large recordsets, especially where large numbers of records need to be grouped together to determine which is the max or min etc. However, the restriction is generally only Access specific, as most SQL engines support deleting directly from a non-updatable query (as defined for Access).

The UPDATE (Flag) process is similar to the following. The fieldnames may well not match yours :
Expand|Select|Wrap|Line Numbers
  1. UPDATE [tblCalls] AS tC INNER JOIN [tblCalls] AS tC2
  2.     ON tC.Number=tC2.Number
  3.    AND tC.Called<tC2.Called
  4. SET tC.SomeTextField='DeleteMe'
The DELETE process is then simply :
Expand|Select|Wrap|Line Numbers
  1. DELETE
  2. FROM [tblCalls]
  3. WHERE [SomeTextField]='DeleteMe'
Avoid using an indexed field as [SomeTextField] as this will impact severely on the performance.
Jun 27 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Drew | last post by:
I have a permission tracking app that I am working on, and I have made the insert page for it. I am having issues on how to prevent duplicates from getting entered. Currently the interface for...
0
by: Jaosn S | last post by:
Thanks in advance for looking at this! I have a simple query that grabs the inventory results between two date periods: SELECT tblCSV.SKU, tblCSV.date, tblCSV.count FROM tblCSV WHERE...
1
by: MHenry | last post by:
Hi, I have a table with duplicate records. Some of the duplicates need to be eliminated from the table and some need not. A duplicate record does not need to be eliminated if the one record...
9
by: Tony Williams | last post by:
I have two tables 1.tblmonth which holds two fields txtmonth and txtqtrlabel and 2. tblmain which holds a number of fields but in particular a field called txtqtrlabel2. The two tables are linked...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
2
by: watcher248 | last post by:
I'm new to Access so please be kind...I'm trying to determine oldest and youngest employee, I'm sure that the line below is copied verbatim, any ideas I would be most grateful, and so would my...
3
allingame
by: allingame | last post by:
Need help with append and delete duplicates I have tables namely 1)emp, 2)time and 3)payroll TABLE emp ssn text U]PK name text
0
by: | last post by:
I'd like to be able to get the path to the oldest folder in whatever directory I'm currently in. Is there a simple way to go about this? I'd like it to run on both OS X and Windows XP. I found...
3
by: Lester | last post by:
I'm driving myself crazy with a problem in trying to translate a query written for Access to that for SQL server. I would think that I would use a trigger, but am not sure how to set it up. We...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.