I have a SQL Table that doesn’t have a primary key but should have which is the account_id, key and index.
But unfortunately, I already have millions of entries before I was able to notice this problem.
I have account_id from 2000001 and upto around 2004000+ and also several keys which should’ve been primary keys so that only the value would be replaced if ever there is an update.
Sample image below,
https://i.imgur.com/g6je2zL.png
There should only be 1 #betaminutes and #online_minute under account_id 2000846 and the value should only be the highest
Is it possible to do a mass delete on each and every account_id for all the different keys I have and only save the entry with the highest value for each account_id’s keys?
Thank you
2
Answers
A large delete will be expensive, you are using. In MySQL, you can use:
Note: If there are ties for the highest value, then this will keep the ties, but your sample data suggests that there are no ties.
You can use the
exists
as follows: