The problem is:
I have got a table of columns (A, B, C) where A+B accounts for a unique key. A few records shall be updated (set is on C) and some records are new, unique A+B keys do not exist in the table. The perfect is INSERT ON DUPLICATE KEY UPDATE, but… Not updated rows (within a considered value for the A column – the same A value for all updates considered) should be deleted. The question is what is the finest way to do it, preferably a shortest query/stored procedure. I found the way around but I am looking for a more specyfic solution to the purpose.
The way I do it is to have a
todeleteflag. Set it to1on all rows before updating, then during the update set updated rows to havetodelete=0. Then delete any rows wheretodeleteis still 1.