Skip to content

Separator in group_concat #638

Answered by lovasoa
DSMejantel asked this question in Q&A
Oct 6, 2024 · 4 comments · 6 replies
Discussion options

You must be logged in to vote

Oh, I see. the problem comes from group concat not allowing the use of both DISTINCT and a custom separator. You can replace

group_concat(distinct nom, CHAR(10) || CHAR(10)) 

with a subquery that does the de duplication separately. Something like

SELECT 
    (SELECT pole FROM poles WHERE poles.id = pole_id) as title,
    'tools' as icon,
    (SELECT group_concat(nom, CHAR(10) || CHAR(10))
     FROM (
         SELECT DISTINCT nom
         FROM intervenants 
         WHERE intervenants.inscription_id = inscription.id
         ORDER BY nom
     )) as description_md,
    json_group_array(json_object(
        'icon', 'tools',
        'color', 'red',
        'description', categorie
    )) as i…

Replies: 4 comments 6 replies

Comment options

You must be logged in to vote
1 reply
@DSMejantel
Comment options

Comment options

You must be logged in to vote
2 replies
@lovasoa
Comment options

@DSMejantel
Comment options

Comment options

You must be logged in to vote
1 reply
@lovasoa
Comment options

Comment options

You must be logged in to vote
2 replies
@lovasoa
Comment options

Answer selected by DSMejantel
@DSMejantel
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants