Ok, so if you need a background, look at my previous question
Finding out which of my records is not a duplicate is pretty simple:
SELECT * FROM eventlog GROUP BY event_date, user HAVING COUNT(*) = 1 ORDER BY event_date, user
This returns all of my non-duplicates. So I decided to move them to another table called "no_duplicates", and then delete them from the original table. Then I could see duplicates in a single table, correct them and add no_dupes back. But for now:
INSERT INTO no_duplicates SELECT * FROM eventlog GROUP BY event_date, user HAVING COUNT(*) = 1 ORDER BY event_date, user
Works like a charm, the following causes an error:
DELETE FROM eventlog GROUP BY event_date, user HAVING COUNT(*) = 1 ORDER BY event_date, user
I assume that although the query returns unique records already in the table, deletion using an aggregate function is not kosher. This is understandable, except that I do not know what else I can do to delete only the records that I deleted. I searched and did not find the syntax "After INSERT kills the records in the source table", and I assume that it will fail anyway, for the same reason as deleting.
So can someone help me find the missing part?
source share