0

I have a table where I set up a Unique Inndex for FieldsA, B and C so that on an automated import I run 4x daily I don't get duplicate records.

However I find myself in need of manually sometimes creating duplicate records using those very same fields.

My overall idea is to, after each import, manually review the data and add the manual duplicates as needed.

Then I'll run a Delete Query to remove the duplicates but only when time difference between them is say 4 hours. That will account for removing the automated Insert of the Duplicate Records but not remove the dupes I add manually minutes apart.

I have a datetime stamp field for each record, is there a way to query differences in time for a givevn day from that field? My basic delete will be:

Delete T1 from Table T1
Inner Join Table T2
On T1.FieldA=T2.FIeldA 
and T1.FieldB=T2.FieldB
and T1.FieldC=T2.FieldC
and T1.ID>T2.ID

but now I'm lookin to add some where on the DateAdded field to only do so if the date/time difference between T1 and T2 is > say 1 Hour or 30 minutes etc.

user3649739
  • 1,829
  • 2
  • 18
  • 28

1 Answers1

0

You may use the TIMESTAMPDIFF function. In your case it will be like this:

TIMESTAMPDIFF(MINUTE, T1.DateAdded, T2.DateAdded) > 90;
Philip Petrov
  • 975
  • 4
  • 8