Reputation: 877
I have one table with two columns parent_string and child string like this
id parent_string child_string
1 0|4#festivals$Festiv NULL
2 0|4#festivals$Festiv 1|4@5#diwali$Deepavali
3 0|4#festivals$Festiv 1|4@6#christmas$Christmas
4 0|8#birthday$Birthday 1|8@9#for-mom$For Mom
5 0|8#birthday$Birthday 1|8@10#for-dad$For Dad
If i want to select id in(1,2,3) then
I want output concat string like following:
0|4#festivals$Festiv~1|4@5#diwali$Deepavali~1|4@6#christmas$Christmas
how to do this?
Upvotes: 0
Views: 312
Reputation: 24012
You can use concat_ws
and group concat
with custom separator
on the fields ...
Example:
select
concat_ws( '|', parent_string, group_concat( child_string separator '|' ) )
from table_ame
group by parent_string
Refer to Documentation:
CONCAT_WS(separator,str1,str2,...)
Upvotes: 1