Is there a way to delete duplicate records based on two fields?
I have a system where people can register for sport events. In the table:
event_registrations
• unique_id
• eventname
• id (person’s id number)
• Name and Surname
One person can apply for many events – id may duplicate
an event may have multiple participants – eventname may duplicate:
--Johnsmith-- --Mountain Cycle--
--Johnsmith-- --Marathnon Walk--
--Linda-- --Mountain Cycle--
--Johnsmith-- --Mountain Cycle--
But a person may not register for a event they have already registered for:
--Johnsmith-- --Mountain Cycle--
--Johnsmith-- --Mountain Cycle--
They Select a event name through a form. Then the form data and their user details is stored in table event_registrations.
Any help would be appreciated
First delete any rows with duplicate
(eventname, id)combinations.Then add the UNIQUE constraint:
Your form that adds registrations should be adjusted accordingly to treat the error it will get from MySQL when a duplicate row is rejected.