0

I have a table called colors. In this table are two fields: color, and is_duplicate. I want to place a 1 in the is_duplicate field if there are more than one of the same values found in the color column.

This is what I have tried so far, but it comes back with errors as I am new to the mysql syntax.

update colors
set is_duplicate = 1
where color 
HAVING COUNT(*) > 1

I am doing this so I can then drop all of the copies of the duplicates and at a later time go back and see which records had duplicates at one time.

Any suggestions? Thank you.

4

1 回答 1

0

尝试这个:

update colors tab1 join (select color, count(*) as num_color
         from colors group by color 
         having count(*) > 1
        ) tab2 on tab1.color = tab2.color       
set is_duplicate = 1
于 2013-11-01T03:28:55.603 回答