2

I'm trying to select multiple columns from multiple tables into one single column as a string (since this is part of a larger query)

Basically what I'm trying to do is make sub-groups of an ID and a Name, The only problem however is that I can't find a way to split these after they already have had a separator assigned to the parent group.

My code:

SELECT 
    GROUP_CONCAT(`mytable1`.`id`, `mytable2`.`name` SEPARATOR  ', ')
FROM `mytable1`
INNER JOIN `mytable2`
    ON `mytable2`.`id` = `mytable1`.`id`

What I'm getting:

127Name, 153Name, 153Name, etc..

What I'm trying to achieve:

127 : Name, 153 : Name, 153 : Name, etc..

Is there any way this is possible?

1 Answer 1

1

Use concat inside group_concat

GROUP_CONCAT(CONCAT(`mytable1`.`id`,' : ', `mytable2`.`name`) SEPARATOR  ', ')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.