Relate Products to duplicated EANS in a relation where 1 product has n EANS. sql language

Asked

Viewed 19 times

1

How could I make the comparison with the EAN of another product without comparing it to the same product... in sql?

CREATE TABLE `produto`(
`idproduto` INT NOT NULL AUTO_INCREMENT,
`nome` VARCHAR(45) NOT NULL,
PRIMARY KEY (`idproduto`)
)

CREATE TABLE `eans` (
`cod_produto` INT NOT NULL,
`ean` VARCHAR(45) NOT NULL,
FOREIGN KEY (`cod_produto`)
REFERENCES `produto` (`idproduto`)  
);
  • put in question the data model, structure of tables, because so it is difficult to help

  • At first you could identify duplicate EANS using the clause HAVING COUN(*) > 1 along with a GROUP BY EANS.

1 answer

0

If you want to identify products that, despite having different codes, have the same EAN try:

SELECT ean, GROUP_CONCAT(cod_produto) 
FROM eans
GROUP BY ean
HAVING COUNT(cod_produto) > 1

If it is not that explain better what you want, if possible with some example.

  • exactly this whine, I’ll try here thank you

Browser other questions tagged

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