I have a database with some fields and I want to apply a unique value constraint to a table:
ALTER TABLE assessment_submissions
ADD CONSTRAINT UC_Question UNIQUE (evaluated_user, evaluator_user, question_id);
But there is some data inside the table that doesn't allow me to put this constraint.
I got an error when I tried to apply the constraint:
SQL error 1062: Duplicate entry 154-154-45 for key UC_Question
Take a look at the image below:
The results on the line that starts with id 131271 and id 131413 have the same values on the fields evaluated_user
, evaluator_user
, and question_id
.
This way it's not possible to apply the constraint.
I deleted the duplicated row, but I still was not able to apply the constraint.
I suppose there are more duplicate data inside that table. How can I find all data that is duplicated inside that table? Which query can I use to do that?
I have no idea where I can start.