I have records that will get imported every hour to a table. The records are often duplicates. I want to delete any duplicates, note which records are new and then copy/move/export them somewhere else.
How can I do this?
I created two tables that are the same. I initially populate data into TableA and then copied everything from TableA into TableB.
INSERT INTO TableB SELECT * FROM TableA;
When new data streams into TableA, I go:
DELETE FROM TableA
WHERE EXISTS
(SELECT *
FROM TableB
WHERE TableA.field1 = TableB.field1);
And then, I do what I need to do with the data in TableA and then copy everything from TableA to TableB again.
INSERT INTO TableB SELECT * FROM TableA;
Repeat as often as new data streams into TableA and repeat. This keeps only "fresh" data in TableA. Please advise if there is a more elegant solution.
Thanks again.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments