Magic of Mysql’s GROUP_CONCAT()

I lived for a long time without knowing about this function, but it is really great when you need to create quick reports.

E.g. imagine that you have three tables:

Users table:

Clubs table:

And a many-to-many relationship table:

What if you needed to see which user belongs to which group, in a human readable format? You could write a query like:

But the result will be messy (though easy to parse for a program afterwards):

If you want to have an instantly human-readable result, you can utilize GROUP_CONCAT() like this:

Much nicer, isn’t it? Beware, this is not standard SQL and it won’t work in e.g. PostgreSQL, but you can utilize something like this in it: