I have a database. id – is a primary key.
id color
1 green
2 red
3 pink
4 pink
5 red
How do I remove repeated colors in SQL? The result will be:
id color
1 green
2 red
3 pink
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In order to remove duplicates from your table, try a statement like this:
In English: Delete all records from
my_tablewhere there is another record inmy_tablewith the same colour but with a lower ID. This will keep the record with the lowest ID per duplicate colour.I suggest that after removing duplicates, you should add a unique constraint as indicated by LolCoder here