Refer to duplicate values in the same table

Asked

Viewed 43 times

0

I’m having trouble making a query to display duplicate values in the same table.

I have a record table of electrical measurements with the following fields:

ID_EQUIPAMENTO, DATA, HORA, FASE_A, FASE_B, FASE_C

Independent of DATA and HORA, I need to identify equal records in the FASE_A, FASE_B, FASE_C in different equipment, pointing out that there are many equipment.

follows image to illustrate better:

inserir a descrição da imagem aqui

  • Right, and so far, what have you tried ? Add the code to the question.

2 answers

1

I believe this should help. I would have been more specific if you had provided more information. Basically what you need is to determine a referential referring to the non-unique records you want to monitor, and in a sub-querie check them through a COUNT(), grouping in a convenient way.

SELECT * FROM Tabela WHERE Referencial in
(SELECT Referencial FROM Tabela GROUP BY Referencial HAVING COUNT(*) > 1)
  • I understood the consultation but still not that, probably not expressed my doubt clearly, even so thank you!

  • 1

    @Rodriggosantana, something that can help is you create a template of the expected result. Something like what was done in this question. I await your editions.

0

Taking into account your information (some superficial) I will assume a solution, I believe it is already necessary for your case.

You can use the HAVING where you can use aggregate functions.

Here’s an example for you to tailor and implement for your problem:

In this table let’s imagine that it has only the fields COD_PRODUTO and DESCRICAO and that it contains records duplicated or triplicate ...

SELECT COD_PRODUTO, DESCRICAO FROM PRODUTOS
GROUP BY
    COD_PRODUTO, DESCRICAO
HAVING COUNT(*) > 1;

If you have a product that is "registered" more than once in the bank, it will be returned in this instruction above.

I hope I’ve helped.

Browser other questions tagged

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