0

Taking this example:

One table of persons [id, name].
One table of colours [id, colour].
One table of associations. (which colours are liked by which people) [id,person_id,colour_id].

I want to select all the persons with id and name as well as a column of the names of the colours each likes separated by comma and space: ", ". One person can like more than just one colour.

How should the query look?

Thank you.

1 Answer 1

4

Did I do good?

SELECT person.id, person.name, GROUP_CONCAT(colour.colour SEPARATOR ', ')
FROM person
JOIN associations ON associations.person_id = person.id
JOIN colours ON colours.id = associations.colour_id
GROUP BY person.id
0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.