Category: MySql

Mysqlx250 3

MySql query to dynamically convert rows to columns

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.

Mysql get field names from table 2

Mysql get field names from table

I am currently developing a backend generator in PHP / MySQL. At some point in order to make the magic happen I needed to get the field names for a table and insert them into a table of my own, in order to store the metadata that I need to create the application.

pivot a table with dynamic columns in mysql 20

Pivot table with dynamic columns in MySQL

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

MySql Pivot Table 25

Pivot a table in MySQL – Tutorial

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.