View linked ID of a duplicate mysql record

Asked

Viewed 60 times

2

I wonder if it is possible to show duplicate records and which id that they are duplicated.

Table Example:

Tabela com 8 linhas e 3 colunas contendo nomes de empresas

I would like to display the duplicate names, but let him also inform me id along.

I made the consultation below:

select count(*) as contador, nome_F
  from comerciantes
 group by nome_f
having count(*) > 1

However this way he only shows me quantity of duplicates and not the id linked. Tabela contendo 4 linhas e 2 colunas com quantidade e nome da empresa

I want him to show not only the amount of duplicates, but also the id.

1 answer

2


You can use the GROUP_CONCAT. In the query below will return duplicate names, next to a list of id concatenated:

select count(nome_f), nome_F, GROUP_CONCAT(id)
  from comerciantes
 group by nome_f
having count(nome_f) > 1

You can better view in the functional example:
http://sqlfiddle.com/#! 9/43b86/5

Browser other questions tagged

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