In some cases pivoting a table is not desired, instead we need to convert rows to columns and append them to the result set without “grouping” them against a specific value. In some cases we simply need to append a column, or columns, for each row and name the new columns something arbitrary like data1, data2, data3, etc.
I have already written a post on how to pivot a table in MySQL, when the rows that we want to pivot into columns are somewhat predefined. Today I am going to show how you can achieve the same result, when the rows that we want to pivot into columns are not predefined but are dynamic instead
Databases are great, especially when they are normalized. Most of the time we (try to) end up in a 3NF database which addresses most of these issues. However occasionally, we come across this problem where you would prefer to have some piece of information in a column, but unfortunately it is in one or more rows. It’s at times like these, that you must know how to pivot a table in MySQL in order to make your life easier.