I have 3 tables: 'task', 'contact' and 'task_contact'. There's a BOOL column 'primary_contact' in 'task_contact' table. At first one task could have 1 or more primary contacts and 1 or more secondary contacts (optional) but now I decided to limit both to 1: so that 1 task can have only 1 primary and 1 secondary contact (optional). But I have an existing table 'task_contact' on the live-server which contains a lot of now inconsistent data.
What I need is to leave only the most recent rows with primary and the secondary (if it does exist) contacts in 'task_contact' table and delete all duplicated by 'primary_contact' rows so that I could apply the UNIQUE constraint for ('task_id', 'primary_contact').
Thanks in advance for any help.