Hi
I have below data .
| Group 5C |
| Group 5B |
| Group 3C |
| Group 4C |
| Group 3E |
| Group 5C(i) |
| Group 4C(i) |
I want to get data like this
Group 5C , Group 5C(i)
Group 5B
Group 3C
Group 4C , Group 4C(i)
Group 3E
Thanks
Hi
I have below data .
| Group 5C |
| Group 5B |
| Group 3C |
| Group 4C |
| Group 3E |
| Group 5C(i) |
| Group 4C(i) |
I want to get data like this
Group 5C , Group 5C(i)
Group 5B
Group 3C
Group 4C , Group 4C(i)
Group 3E
Thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Tuhin PaulRank #7 · 71.9K reputationPosted Jun 10, 2023, 7:13 AM EDT
SELECT CONCAT(group_name, IF(group_name LIKE '%(i)', '', CONCAT(' , ', (SELECT group_name FROM groups g2 WHERE CONCAT(g1.group_name, '(i)') = g2.group_name)))) AS grouped_names FROM groups g1 GROUP BY group_name ORDER BY group_name;This query will concatenate the group names together based on the specified conditions. The IF statement is used to exclude the "(i)" suffix for group names that already have it. The subquery is used to retrieve the corresponding "(i)" group name, if it exists, and concatenate it with the original group name.