Skip to content
Advertisement

Two results in a row with two columns and group

I am trying to mix multiple results on a single line

Here the data example:

And mixed with:

I want this result:

Now I correctly receive users using GROUP_CONCAT(DISTINCT studentID SEPARATOR ‘,’) in SELECT but i can’t use it again. I have tried CASE but have not succeeded.

Advertisement

Answer

You can use conditional aggregation and a correlated subquery:

The correlated subquery eliminates the need for group_concat(distinct), which is more expensive than just group_concat().

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement