I have a table with the following structure:
ID | FK_1 | FK_2 | MONTH | STATE
12 171 26 4 APPROVED
13 171 26 4 SUPER_APPROVED
14 56 32 4 APPROVED
15 45 34 4 SUPER_APPROVED
16 45 34 4 APPROVED
17 22 65 4 REJECTED
I need to remove duplicate rows so that there is only one row with each possible combination of FOREIGN_KEY_1, FOREIGN_KEY_2 and MONTH.
If there are two rows for that combination (such as row ids 12 & 13 or 15 & 16 above) I want to only keep the row that has the state SUPER_APPROVED.
After the script has been run I would expect the following data to be in the table (based on example data above):
ID | FK_1 | FK_2 | MONTH | STATE
13 171 26 4 SUPER_APPROVED
14 56 32 4 APPROVED
15 45 34 4 SUPER_APPROVED
17 22 65 4 REJECTED
Any help would be greatly appreciated