Today I was trying to find duplicate rows in db table rows, but besides finding them, I needed to get their indexes in order to address them.

Given
The table structure is simple:
id – index, unique
name – varchar
To find all the duplicate names you just hit the following:

So, adding id into the above SELECT statement will only return one of the several duplicate rows’ indexes.

Concat ids
So, let us rather concatenate ids using GROUP_CONCAT:

 *DISTINCT inside the function is redundant here, but it exposes the function’s ability.
Result:

So, name is one, while the ids where there are duplications are concatenated, returned as a string.