a rookie MYSQL user …. I have a simple MySQL query that returns values, and uses the GROUP_CONCAT function:
SELECT Productid, Name, GROUP_CONCAT(value)
FROM search_export
Group By Productid, Name;
Productid Name GROUP_CONCAT(value)
666056542 Brand Name Netgear
1054677552 Ethernet Technology Gigabit Ethernet
665655662 Form Factor Wall Mountable,Desktop
56565765 Media Type Supported Twisted Pair
However, I need to transpose the query so it returns ‘Name’ as seperate columns, not a row. Is this possible at all with MySQL?
You need to perform a
PIVOToperation, which is not supported natively in MySQL (unlike some other RDBMS).The closest you can get is to construct SQL along the following lines:
If the possible
Namevalues are dynamic, you could generate such SQL in a higher level language from the results of:Indeed, one could even use SQL itself:
Note that if there are a lot of different
Namevalues, you may need to increasegroup_concat_max_lenfrom its default of 1KiB.