Find duplicate records within same year (1 Viewer)

asid

Registered User.
Local time
Today, 21:41
Joined
Jan 25, 2006
Messages
22
Hi
I have generated a table of dublicates records.
I want to now filter all of those duplciates (people) that have been contacted more than once wihin a year.

Eample

personID contactDate
100 01/10/2012
100 06/11/2012
100 11/11/2017
show this as the first two reocords were withn the same year

101 01/12/2012
101 01/15/2014
dont show

How do I do this, maybe a query is not the best way?
 

JHB

Have been here a while
Local time
Today, 11:41
Joined
Jun 17, 2012
Messages
7,732
..
How do I do this, maybe a query is not the best way?
A query is the perfect way:

  • First create a query, which find all the person who are contacted more as 1 time per year, call the query "ContactedTimesPerYear"
  • Then create a query which list the person and the date, joined by the first query on the personId and the Year(contactDate). Remark the query can only be viewed in SQL view.
Sample database is attached, run the query "FinalQuery".
 

Attachments

  • Database46.accdb
    392 KB · Views: 64

asid

Registered User.
Local time
Today, 21:41
Joined
Jan 25, 2006
Messages
22
Thank you, close but when I say within a year, that is not the same calendar year but a year from the previous contact.
So this should show as a the second contact was only a month later?

personID contactDate
105 15/12/2008
105 1/01/2009
105 1/01/2017
 

plog

Banishment Pending
Local time
Today, 04:41
Joined
May 11, 2011
Messages
11,668
First, "within a year" is hard to define at the edges. What date is 1 year after February 29, 2016? February 28th or March 1st?

So, using JHB's database, what I did is wrote 2 queries to determine the days difference between a contact's last contact date. The first determines the last date prior to the current one:

Code:
SELECT T.personID, T.contactDate, (SELECT Max(tblPerson.contactDate) FROM tblPerson where tblPerson.personID = T.personID AND tblPerson.contactDate<T.contactDate) AS LastContactDate
FROM tblPerson AS T;

PAste the above SQL into Access and name it 'sub1'. Then on top of that, I built another query to determine the total days between those two:

Code:
SELECT sub1.personID, sub1.contactDate, sub1.LastContactDate, DateDiff("d",[LastcontactDate],[ContactDate]) AS LastContactDays
FROM sub1;

Paste that into a new query and run it. Then add your criteria and GROUP appropriately to get the exact results you want.
 

asid

Registered User.
Local time
Today, 21:41
Joined
Jan 25, 2006
Messages
22
Thanks that did work. In the end I used vba to loop through a record set, there were several million records and the queries struggled.
 

Users who are viewing this thread

Top Bottom