Need help in achieving the output provided below.Using the below query but its not removing the duplicate values if there are multiple values coming :
select databasename, tablename,
CASE when LENGTH(commentstring) > 0 and (upper(CommentString) like 'AB - %' or
upper(CommentString) like 'AB-%' or upper(CommentString) like 'ABA-%'
or upper(CommentString) like 'AB_%') then
(cast(regexp_substr(commentstring, '(\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]
{2,6}\b)', 1, 1, 'i') as varchar(128))
|| coalesce(';' ||cast(regexp_substr(commentstring, '(\b[A-Za-z0-9._%+-]+@[A-Za-z0-
9.-]+\.[A-Za-z]{2,6}\b)', 1, 2, 'i')as varchar(128)), '')
|| coalesce(';' ||cast(regexp_substr(commentstring, '(\b[A-Za-z0-9._%+-]+@[A-Za-z0-
9.-]+\.[A-Za-z]{2,6}\b)', 1, 3, 'i')as varchar(128)), '')
|| coalesce(';' ||cast(regexp_substr(commentstring, '(\b[A-Za-z0-9._%+-]+@[A-Za-z0-
9.-]+\.[A-Za-z]{2,6}\b)', 1, 4, 'i')as varchar(128)), '')
|| coalesce(';' ||cast(regexp_substr(commentstring, '(\b[A-Za-z0-9._%+-]+@[A-Za-z0-
9.-]+\.[A-Za-z]{2,6}\b)', 1, 5, 'i')as varchar(128)), '')) end as emailid
from tablesv
Input :
test1,sample1,abc@test.com;cde@test.com
test2,sample2,fgh@test.com;fgh@test.com,ghi@test.com
test3,sample3,hij@test.com;jkl@test.com;hij@test.com
Ouput: With the above query, not able to remove the duplicate email id.I need to keep one email if its duplicate in row.
test1,sample1,abc@test.com;cde@test.com
test2,sample2,fgh@test.com;ghi@test.com
test3,sample3,hij@test.com;jkl@test.com