Names and values are concatenated into strings and grouped by id. We need an aggregate function,
that concatenates strings for that. Here are some solutions for different sql databases.
MySql
This case is most easy one. Lucky users already have the GROUP_CONCAT(expr) function. This
query should give the answer.
PostgreSql
The solution here is a bit more difficult, but nevertheless easy enough. We need to create our own
aggregate function and use it in our query.
Here we used already existing function to concatenate text fields textcat, but we could write
our own.
MsSql
Since version 2005 it became also possible to write your own aggregate function in MsSql, but here
I provide another solution using inner select and xml path.