Check duplicate items and update a column in all but one

0

I have a table of products that bring information from an XML, and another table in the system that basically receives these products after approval (we have an interface to define what goes in or not, basically changing a value in the product so that it does not get visible but continue at the base). Products that enter the XML often bring several similar items, change only a few parameters in the product SKU, due to the difference in size of the clothes, as the example:

What I would like to do is the following:

How can I select all duplicate results, minus one of them, and update the imported column of the ones that the select fetch. Imported as 0 hides the product from the approval queue, so the queue will not show several times the same product that basically only has the different SKU.

Thank you guys.

    
asked by anonymous 15.12.2016 / 16:19

1 answer

0

I think a GROUP BY would work, something like:

UPDATE tabela SET importado = 1 WHERE sku <> FIRST(sku) GROUP BY nome

Just test with a SELECT before to see if you are selecting the right records

SELECT * FROM tabela WHERE sku <> FIRST(sku) GROUP BY nome 
    
15.12.2016 / 16:27