I am tracking history of changes to rows in a table that is filled with a trigger on update of another table. It tracks the revision history of the main table.
Often, my users, out of habit, will hit the SAVE button even though they have not changed anything in the record, and the system will still record a copy of that row as a revision in the history table, despite the fact that nothing has changed.
Lets say I have the tables with columns like this (although mine have about 40+ cols):
Main Data:
id, name, phone, task, dob, timestamp, note, drivername, student, doctor, userid
On Update of Main Data, insert into history:
revisionid, revisiontime, id, name, phone, task, dob, timestamp, note, drivername, student, doctor, userid
The solutions to find duplicate records presented in this site and on other sites all will work well, if I wanted to list out the columns by hand.
The problem is that there are many many columns, and that I often add columns and don't want to rewrite this query every time.
When the user saves, often only the timestamp will change. What I want to do is keep only the revisions where values have changed (ignoring the revisionid and revisiontime which always change).
In the query, I dont want to list any other column names besides the columns which i want to ignore. Is it possible?
Pseudo code:
DELETE [rows, except one] FROM historytable WHERE [all columns match values] EXCEPT [these few columns which can still be different and be deleted]
Here are a few reference questions:
Deleting duplicate rows from a table
How to check for duplicates in mysql table over multiple columns