I have table HumanNames
The input is
|HumanName |
|------------- |
|Kamil |
|Azer |
|John |
|Elmir |
|Kamal |
|Elmar |
|Orxan |
|Elnar |
|NamesWhichLikes |
|------------- |
|Kamil,Kamal |
|Elmir,Elmar,Elnar|
| |
Try this using listagg
and group by
on soundex
of name:
with your_table (HumanName) as (
select 'Kamil' from dual union all
select 'Azer' from dual union all
select 'John' from dual union all
select 'Elmir' from dual union all
select 'Kamal' from dual union all
select 'Elmar' from dual union all
select 'Orxan' from dual union all
select 'Elnar' from dual
)
------ Test data setup ends here ------
select
listagg(humanname,',') within group (order by humanname) nameswhichlikes
from your_table
group by soundex(humanname)
having count(*) > 1;
Produces:
+---------------------------+
| NAMESWHICHLIKES |
+---------------------------+
| Elmar,Elmir,Elnar |
+---------------------------+
| Kamal,Kamil |
+---------------------------+
In case of duplicate names:
select
listagg(humanname,',') within group (order by humanname) nameswhichlikes
from (select distinct humanname from your_table)
group by soundex(humanname)
having count(*) > 1;