Reputation: 562
have a newly created MySQL table and trying to add a unique constraint on one of the columns (phone_number), but I keep getting the following error:
"ERROR 1062 (23000): Duplicate entry for..."
Attached screenshot of the table and also output.
Forgot to make sure records are unique based on phone number and now trying to remedy this.
Any idea on why this error is showing and how we can still add a unique constraint? Thanks
Upvotes: 0
Views: 814
Reputation: 39704
You can try to find duplicates
SELECT phone_number, COUNT(*) c FROM leads GROUP BY phone_number HAVING c > 1;
Get rid of duplicates and then unique constraint will work.
Upvotes: 1