Remove duplicity in two columns

Asked

Viewed 153 times

-1

I would like to know how to resolve the following situation

I have a view where the item code is duplicated by the key of another column ex:

data------cod_prod-----descricao----- chave----------------------------fornecedor

12/07/18-----3-----------WALLMART

12/07/18-----3-----------00060122110060115217--PAO DE ACUCAR

I need you to return just one record but there are several records with this type of precise duplicity of a record for each cod_product.

ex: data----cod_prod---Description---- key--------------------supplier

12/07/18-----3-----------WALLMART

  • You want to change the field cod_prod of the records with this field duplicated or want to delete the records with this field duplicated to at last only have 1 imputation for each cod_prod ?

2 answers

0

From what I understand. I think you need something like this. SQL Server, give feedback if it helped.

SELECT [data]
      ,cod_prod
      ,descricao
      ,(SELECT TOP 1 chave FROM [teste].[dbo].[products] B WHERE B.cod_prod = A.cod_prod) AS chave 
      ,(SELECT TOP 1 fornecedor FROM [teste].[dbo].[products] B WHERE B.cod_prod = A.cod_prod) as fornecedor
FROM [teste].[dbo].[products] A
GROUP BY A.data, A.cod_prod, A.descricao

0

Try this, I hope it helps

SELECT * FROM nome_tabela
    WHERE
     Coluna1 NOT IN (
        SELECT Coluna1 FROM nome_tabela
        GROUP BY Coluna1
        HAVING Count(*) > 1
     )
    And Coluna2 NOT IN (
        SELECT Coluna2 FROM nome_tabela
        GROUP BY Coluna2
        HAVING Count(*) > 1
     )

Browser other questions tagged

You are not signed in. Login or sign up in order to post.