Hello everyone. Finding duplicates and deleting duplicates is rather simple. However, I'm trying to run a query that only deletes the extra copies of my duplicates while leaving one in the table. Right now when I run my delete query, it deletes ALL of the duplicates when I really need to keep at least one of those records.
Here is my current SQL Statement:
DELETE Hats.*, Hats.PersonsName
FROM Hats
WHERE (((Hats.PersonsName) In (SELECT [PersonsName] FROM [Hats] As Tmp GROUP BY [PersonsName] HAVING Count(*)>1 )));
I have a HUGE table that lists customers names and how many hats they've bought. All I need is to know how many customers I have had over the past quarter, so I just need a count of each individual customer. If a customer has bought hats from me on more than one occasion, there will be multiple records in my table for each transaction. This will cause the customers name to be listed more than once.
If I try to count the number of customers in my table, I will end up with a number too high because the count will include some of the same customers more than once. I can run a find duplicate query and delete them by hand, but the table is too large to delete them one by one.
Does anyone know of a good SQL that would solve this problem? Any help would be greatly appreciated! Thanks in advance!